On Fri, Mar 7, 2008 at 12:51 PM, Poli García <[EMAIL PROTECTED]> wrote:
> Hi !
> I'm having an issue with URL parameters. I have these routes mapped on
> my routing.py:
>
> > map.connect('/a_url_path/:param1/:param2', controller='some_controller',
> action='an_action')
> >
> > map.connect('/another_url_path/', controller='some_controller',
> action='another_action')
>
> and some_controller.an_action defined as:
>
> > def an_action(self, param1, param2):
> > # Some work with param1 and param2
> > return render('/some_template.mako')
>
> On some_template.mako I have an anchor defined as:
>
> > ${h.link_to('A Link', h.url_for(controller='some_controller',
> action='another_action'))}
> >
>
> The problem occurs when I navigate to /a_url_path/a_value/another_value. The
> link on the page is rendered as
> /another_url_path?param1=a_value¶m2=another_value. It's like all URL
> parameters are propagated to the links. This doesn't happen always.. and I
> cannot figure out the occurrence pattern. If I name the second route and
> create the link using the name of the route, the parameters are not
> propagated.
>
> Can someone tell me how to avoid this?
The Routes algorithms are too complex and occasionally lead to
situations like this. Your best bet is to use named routes, but even
that can fail sometimes. The problem is that 'another_url_path' has
no variables in it, so url_for is choosing it when it shouldn't. When
I've encountered this -- mainly with links to static files -- I've
just tried different things till it works, or used hardcoded URLs if
it just won't.
Routes 2 will simplify the algorithms greatly, and probably require
all routes and url_for calls to use route names, so that should
eliminate this problem in a couple months. You will have to change
your routing rules so be prepared. (Although you'll be able to stick
with Routes 1 if you're happy with your current routing rules.)
--
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
-~----------~----~----~----~------~----~------~--~---