Skip to content

Instantly share code, notes, and snippets.

@davidwtbuxton
Created May 25, 2012 14:52
Show Gist options
  • Save davidwtbuxton/2788556 to your computer and use it in GitHub Desktop.
Save davidwtbuxton/2788556 to your computer and use it in GitHub Desktop.
Decorated views and exceptions in Bottle
import bottle
import functools
def decorate(func):
"""Prints the arguments."""
@functools.wraps(func)
def wrapper(*args, **kwargs):
print args, kwargs
return func(*args, **kwargs)
return wrapper
@bottle.route('/d')
@decorate
def home2():
return "Welcome decorated"
@bottle.route('/e')
@decorate
def home2():
raise bottle.HTTPError
if __name__ == "__main__":
bottle.run(debug=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment