I have some code I want to run for every request that comes into Flask-- specifically adding some analytics information. I know I could do this with a decorator, but I\'d rather
Flask has dedicated hooks called before and after requests. Surprisingly, they are called:
Both are decorators:
@app.before_request
def do_something_whenever_a_request_comes_in():
# request is available
@app.after_request
def do_something_whenever_a_request_has_been_handled(response):
# we have a response to manipulate, always return one
return response