Skip to content

Instantly share code, notes, and snippets.

@mruser
Last active August 6, 2016 03:18
Show Gist options
  • Save mruser/8187296 to your computer and use it in GitHub Desktop.
Save mruser/8187296 to your computer and use it in GitHub Desktop.
Unfortunately, this seems like the best way to do trailing slash routing in bottle 0.9.6
import bottle
# monkey patch bottle to strip trailing slash if result not found
app = bottle.app()
router_match = app.router.match
def our_match(environ):
try:
targets, urlargs = router_match(environ)
except HTTPError as e:
if e.status == 404 and environ['PATH_INFO'].endswith('/'):
environ['PATH_INFO'] = environ['PATH_INFO'][:-1]
targets, urlargs = router_match(environ)
else:
raise
return targets, urlargs
app.router.match = our_match
@taojy123
Copy link

taojy123 commented Aug 6, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment