Trailing slashes in Pylons Routes
Question
What is the best way to make trailing slashes not matter in the latest version of Routes (1.10)? I currently am using the clearly non-DRY:
map.connect('/logs/', controller='logs', action='logs')
map.connect('/logs', controller='logs', action='logs')
I think that turning minimization on would do the trick, but am under the impression that it was disabled in the newer versions of Routes for a reason. Unfortunately documentation doesn't seem to have caught up with Routes development, so I can't find any good resources to go to. Any ideas?
Solution
There are two possible ways to solve this:
Personally I don't like the trailing slash, because if you have a uri like:
You should be able to get the same data in xml format by going to:
OTHER TIPS
The following snippet added as the very last route worked for me:
map.redirect('/*(url)/', '/{url}',
_redirect_code='301 Moved Permanently')
http://www.siafoo.net/snippet/275 has a basic piece of middleware which removes a trailing slash from requests. Clever idea, and I understood the concept of middleware in WSGI applications much better after I realised what this does.