'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.

Asked By: blueblank

||

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.

Answered By: Drakekin
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.