I was going through a flask application and found the use of @app.teardown_request.
Can anyone please demystify the real reason of using @app.teardown_request rather than @app.teardown_appcontext?
In other words what exactly is the difference?
@app.teardown_appcontext - Bind a function after each request, even if an exception is encountered.
@app.teardown_request - Registers a function to be called at the end of each request whether it was successful or an exception was raised. It is a good place to cleanup request scope objects like a database session/transaction.
https://github.com/pallets/flask-sqlalchemy/issues/379
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With