Search code examples
pythonflasklifecycle

Does Flask support some kind of life cycle methods?


Sanic framework supports life cycle methods such as before_server_start, after_server_start, before_server_stop and after_server_stop.

Is there something similar in Flask like this ?

I know there is a before_request and after_request, but I'm looking for something before application is even started. I need to query a database to check if there is a certain entry in it. If there is, do some processing on that data and then run flask app.


Solution

  • You could look at an Application Factory pattern, which would allow you to perform processing before the app object is created.