Created
September 30, 2014 01:04
-
-
Save Kellel/0beadaff910d72ea317e to your computer and use it in GitHub Desktop.
Force trailing slash in bottle routes
This file contains 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
from functools import wraps | |
def force_slash(fn): | |
@wraps(fn) | |
def wrapped(*args, **kwargs): | |
if request.environ['PATH_INFO'].endswith('/'): | |
return fn(*args, **kwargs) | |
else: | |
redirect(request.environ['SCRIPT_NAME'] + request.environ['PATH_INFO'] + '/') | |
return wrapped | |
@get('/') | |
@force_slash | |
def index(): | |
return "This path ends with a slash!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment