Yes, because the same route can't be both redirecting and non-redirecting.
If you wanted to accept both forms in one route, you could do it with
a requirement regex.
map.connect("/c/{id:\d+[_/]\d+}")
That would pass 'id' in the form "123_456" or "123/456". The
controller would have to accept both forms. Or you could transform one
to the other using a condition function:
def canon_id(environ, routing_args):
routing_args["id"] = routing_args["id"].replace("/", "_")
return True
map.connect(..., conditions={"function": canon_id})
But the redirect strategy is better because it standardizes the URL at
the client and and in any bookmarks they make, and fulfills the HTTP
principle that there should be exactly one URL to each resource.
PS. I don't know why you don't need the "R" prefix for route patterns
containing backslashes, but for some reason it seems to work.
--Mike
On Fri, Aug 27, 2010 at 3:31 AM, lwolf <[email protected]> wrote:
> I think you need to create two routes:
>
> map.connect('/c/{id}', controller='somecontroller', action='some')
> map.redirect('/c/{item1}/{item2}', '/c/{item1}_{item2}')
>
> P.S.accidentally clicked spamreport..sorry)
>
>
> On 27 авг, 12:05, Alexander Zhabotinskiy <[email protected]>
> wrote:
>> Is it possible to make at routes mapper like:
>>
>> /c/2010/1234 redirect to /controller/action/2010_1234, but leave /c/
>> 2010_1234 working
>
> --
> 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.
>
>
--
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.