url_for() constrcut URL with MultiDict parameters?

27 views
Skip to first unread message

jerry

unread,
Apr 28, 2008, 9:19:50 PM4/28/08
to pylons-discuss
Hi,

Is there a way to construct URLs like """/controller/action/id?
q=1&q=2""" with url_for()?

Thanks in advance!

Jerry

Mike Orr

unread,
Apr 29, 2008, 12:38:32 AM4/29/08
to pylons-...@googlegroups.com
On Mon, Apr 28, 2008 at 6:19 PM, jerry <jerry...@gmail.com> wrote:

> Is there a way to construct URLs like """/controller/action/id?
> q=1&q=2""" with url_for()?

I don't think so. If there's demand for this we can turn a list of
values into multiple parameters. Does MultiDict offer anything that
would help with this?

--
Mike Orr <slugg...@gmail.com>

Jonathan Vanasco

unread,
Apr 29, 2008, 1:38:21 AM4/29/08
to pylons-discuss
On Apr 29, 12:38 am, "Mike Orr" <sluggos...@gmail.com> wrote:
> On Mon, Apr 28, 2008 at 6:19 PM, jerry <jerryji1...@gmail.com> wrote:
> >  Is there a way to construct URLs like """/controller/action/id?
> >  q=1&q=2""" with url_for()?
>
> I don't think so.  If there's demand for this we can turn a list of
> values into multiple parameters.  Does MultiDict offer anything that
> would help with this?

i have a function in helpers, my_url_for , which wraps url_for and
does some misc stuff depending on context. an approach like that
might help you get your task done.

Mike Orr

unread,
Apr 29, 2008, 2:03:06 AM4/29/08
to pylons-...@googlegroups.com

What else does it do?

--
Mike Orr <slugg...@gmail.com>

jerry

unread,
Apr 29, 2008, 11:42:06 AM4/29/08
to pylons-discuss
Hi Mike,

Thanks for the response.

I mentioned MultiDict as a convenient term to convey the idea in my
question, not that I know or thought it would help with the
implementation.

As for the demand, I have a form with a list of checkbox input items
for viewing the details of selected one(s). The receiving controller
will naturally have multi-parameter URL like /details?q=1&q=2 . Now I
want to further enable adding more items in the details viewing list
and need to have another form with probably hidden input items q=1 and
q=2, finally when paging is involved for this form, the pager links
will have to inherit the information of the existing parameters
q=1&q=2, hence the demand.

However, it really doesn't seem to be an appealing design and I think
I'm probably better off sticking with the more RESTful URL like
details/1;2

Cheers,
Jerry

On Apr 29, 12:38 am, "Mike Orr" <sluggos...@gmail.com> wrote:
> On Mon, Apr 28, 2008 at 6:19 PM, jerry <jerryji1...@gmail.com> wrote:
> > Is there a way to construct URLs like """/controller/action/id?
> > q=1&q=2""" with url_for()?
>
> I don't think so. If there's demand for this we can turn a list of
> values into multiple parameters. Does MultiDict offer anything that
> would help with this?
>
> --
> Mike Orr <sluggos...@gmail.com>

Ian Bicking

unread,
Apr 29, 2008, 12:44:08 PM4/29/08
to pylons-...@googlegroups.com
jerry wrote:
> Hi Mike,
>
> Thanks for the response.
>
> I mentioned MultiDict as a convenient term to convey the idea in my
> question, not that I know or thought it would help with the
> implementation.
>
> As for the demand, I have a form with a list of checkbox input items
> for viewing the details of selected one(s). The receiving controller
> will naturally have multi-parameter URL like /details?q=1&q=2 . Now I
> want to further enable adding more items in the details viewing list
> and need to have another form with probably hidden input items q=1 and
> q=2, finally when paging is involved for this form, the pager links
> will have to inherit the information of the existing parameters
> q=1&q=2, hence the demand.

I'm not 100% clear on what you want to do, but probably {'q': ['1',
'2']} will get this for you. You can get a dictionary like this from a
MultiDict with req.POST.mixed().


--
Ian Bicking : ia...@colorstudy.com : http://blog.ianbicking.org

Mike Orr

unread,
Apr 29, 2008, 4:37:07 PM4/29/08
to pylons-...@googlegroups.com

Added to the Routes 2 spec for consideration. (No promises yet.)
http://wiki.pylonshq.com/display/routes/Routes+2+Spec

Ben might implement it in Routes 1; I don't deal with that. You can
increase the chances of getting it done by filing a bug report at
routes.groovie.org.

On second thought, I don't think MultiDict will help because these are
keyword args passed by the user, so they'll come in an ordinary dict.

--
Mike Orr <slugg...@gmail.com>

Ian Bicking

unread,
Apr 29, 2008, 4:40:35 PM4/29/08
to pylons-...@googlegroups.com
Mike Orr wrote:
> Added to the Routes 2 spec for consideration. (No promises yet.)
> http://wiki.pylonshq.com/display/routes/Routes+2+Spec
>
> Ben might implement it in Routes 1; I don't deal with that. You can
> increase the chances of getting it done by filing a bug report at
> routes.groovie.org.
>
> On second thought, I don't think MultiDict will help because these are
> keyword args passed by the user, so they'll come in an ordinary dict.

Correct, but **request.POST.mixed() should work okay.

Reply all
Reply to author
Forward
0 new messages