@app.teardown_appcontext
def shutdown_session(exception=None):
 db_session.remove()

@ app . teardown_appcontext def shutdown_session ( exception = None ) : db_session . remove ( )
automatically remove database sessions at the end of the request .