Skip to content Skip to sidebar Skip to footer

Flask Before_request And Teardown_request For Db Connections

According to the Flaskr tutorial, db connection should be opened and closed before each session: @app.before_request def before_request(): g.db = connect_db() @app.teardown_requ

Solution 1:

SQLAlchemy doesn't know about your Flask application. So, if you want to use pure SQLAlchemy you need to manage connections.

Dealing with these topics by yourself without enough knowledge on db connections, persistent connections and connection pooling may lead to very poor performance and errors. Best practice is to use Flask-SQLAlchemy to abstract db connection management.

Post a Comment for "Flask Before_request And Teardown_request For Db Connections"