1. Create function something like :
def add_auto_route(name, pattern, **kw):
config.add_route(name, pattern, **kw)
if not pattern.endswith('/'):
config.add_route(name + '-auto', pattern + '/')
def redirector(request):
from pyramid.httpexceptions import HTTPMovedPermanently
return HTTPMovedPermanently(request.route_url(name))
config.add_view(redirector, route_name=name + '-auto')
2. Import that function in __init__.py
3. Now instead of using 'config.add_route' use 'add_auto_route'. e.g.
Instead of using 'config.add_route('home', '/index')' use
add_auto_route('home', '/index')
It will create 2 routes, one with you provided & second route with slash.
Hope it will be useful.
Thanks & Regards
Aniruddha Gaikwad
==============================================================
*With the new day, comes new strength and new thoughts. *
On Sun, May 11, 2014 at 4:09 AM, Laurence Rowe <[email protected]>wrote:
> I've run into this too, but haven't gotten around to implementing a
> solution yet. It's an artefact of the WSGI spec inherited from CGI. With
> mod_wsgi you can access the unescaped (but pre any url rewriting) value in
> REQUEST_URI. I'm not sure waitress puts this into the environment too. You
> could have a tween or NewRequest subscriber set the unescaped PATH_INFO
> from REQUEST_URI before url dispatch.
>
> Traversal will be a bit trickier. Following the URI spec grammar would
> suggest splitting first on '/' then unescaping each segment individually.
> Implementing this in a Pyramid app would likely involve subclassing the
> traverser.
>
> Laurence
>
>
> On Thursday, 8 May 2014 13:22:13 UTC-7, Achim Domma wrote:
>>
>> Hi,
>>
>> I have the following two routes in my application:
>>
>> /{base_id}/{sub_id}/{some_text}
>> /{base_id}/{sub_id}
>>
>> Obviously I assume that none of these parts contains a slash, which has
>> just proven to be wrong. ;-) I have control over some_text, so I can make
>> sure, that it will not contain a slash, but I have to accept slashes in
>> sub_id. I tried to encode them as %2F, but I found out that those are
>> decode before reaching Pyramid. My last resort would be a "greedy" pattern
>> for sub_id, so some_text should contain the value after the last slash and
>> sub_id everything between the second and the last slash. I know that this
>> does not work with the default url matching and that it would be a hack,
>> but is there some way to do that with pyramid? I would be happy to accept
>> more or less every not too intrusive hack.
>>
>> cheers,
>> Achim
>>
> --
> You received this message because you are subscribed to the Google Groups
> "pylons-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/pylons-discuss.
> For more options, visit https://groups.google.com/d/optout.
>
--
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/pylons-discuss.
For more options, visit https://groups.google.com/d/optout.