Skip to content

Instantly share code, notes, and snippets.

@Kellel
Created September 30, 2014 01:04
Show Gist options
  • Save Kellel/0beadaff910d72ea317e to your computer and use it in GitHub Desktop.
Save Kellel/0beadaff910d72ea317e to your computer and use it in GitHub Desktop.
Force trailing slash in bottle routes
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