Created
May 25, 2012 14:52
-
-
Save davidwtbuxton/2788556 to your computer and use it in GitHub Desktop.
Decorated views and exceptions in Bottle
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 | |
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