'before_filter' equivalent w/ flask
Question:
After some time working with ruby, I’m back to python. I’m working with the flask framework.
How do I implement a filter to run a method on the request at the start the controller action without putting the same code in every controller? My first guess is to construct a decorator of some sort(e.g. @before_request
but that did not seem it on first glance). I’m just getting (re)acquainted with python and there are few things just out of reach, so any input appreciated. The equivalent is a before_filter
in Rails or before do method in Sinatra.
Answers:
There is a @app.before_request
constructor available as shown in the SQLite pattern given in the docs. This is run on every request.
After some time working with ruby, I’m back to python. I’m working with the flask framework.
How do I implement a filter to run a method on the request at the start the controller action without putting the same code in every controller? My first guess is to construct a decorator of some sort(e.g. @before_request
but that did not seem it on first glance). I’m just getting (re)acquainted with python and there are few things just out of reach, so any input appreciated. The equivalent is a before_filter
in Rails or before do method in Sinatra.
There is a @app.before_request
constructor available as shown in the SQLite pattern given in the docs. This is run on every request.