Last active
August 6, 2016 03:18
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, Official solution now: http://www.bottlepy.org/docs/dev/recipes.html?highlight=slash