Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'before_filter' equivalent w/ flask

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.

like image 573
blueblank Avatar asked Nov 14 '22 05:11

blueblank


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

like image 89
Drakekin Avatar answered Dec 07 '22 23:12

Drakekin