[FIXED] 'before_filter' equivalent w/ flask


After working with Ruby for a while, I returned to Python. I am using flask framework.

How can I implement a filter that runs a method on a request when a controller action starts without putting the same code in every controller? My first guess is to create some kind of decorator (e.g. @before_request but it didn’t seem that way at first glance). I’m just getting (re)familiar with Python and I have very little out of reach, so any input would be greatly appreciated. The equivalent is Rails’ before_filter or Sinatra’s before do method.


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

Answer Checked By – Laura B. (Easybugfix Admin)

Leave a Reply

(*) Required, Your email will not be published