On Fri, Dec 17, 2010 at 9:19 AM, neurino <[email protected]> wrote:
> I have a dynamic form generator that uses request params to generate
> fields.
>
> Let's say I have, for example
>
> myReqParam = {
> id:1
> action:"edit"
> }
>
> and would like pylons.url to generate this url:
>
> http://127.0.0.1:5000/controlpanel/formgen?id=1&action=edit
>
> it's a very common situation
>
> If not reserved words like "id" and "action" are used I can issue
>
> h.url(controller="controlpanel", action="formgen", **myReqParams)
>
> but not with a dictionary like the above...
You can't use a variable as a query param if the same variable is a
path variable or constant in the relevant route. All Pylons routes
define 'action', and a few define 'id'. It shouldn't matter if you use
keyword args or **myReqParams because the same variable can't overlap
between the two.
The solution is to use ``webhelpers.util.update_params`` to add the
query parameters:
h.update_params(url(controller="controlpanel", action="formgen"),
id=1, action="edit")
Also, 'url' is a standard template variable in Pylons 1, so you don't
need h.url in templates.
> I tried to add a trailing slash like in formalchemy but it's not
> stripped.
I don't understand the question. If the route is defined with a
trailing slash, it will be generated with one.
>>> mapper.connect("abc", "/abc/")
>>> url("abc")
'/abc/'
>>> url("/lala/", id=1)
'/lala/?id=1'
--
Mike Orr <[email protected]>
--
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/pylons-discuss?hl=en.