teardown_request() — flask Function Reference
Architecture documentation for the teardown_request() function in scaffold.py from the flask codebase.
Entity Profile
Dependency Diagram
graph TD 6b5643e0_f84e_da48_c887_e62428f07404["teardown_request()"] a813bd5c_bf41_d926_8dde_6a113d5e0018["Scaffold"] 6b5643e0_f84e_da48_c887_e62428f07404 -->|defined in| a813bd5c_bf41_d926_8dde_6a113d5e0018 style 6b5643e0_f84e_da48_c887_e62428f07404 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
src/flask/sansio/scaffold.py lines 508–539
def teardown_request(self, f: T_teardown) -> T_teardown:
"""Register a function to be called when the request context is
popped. Typically, this happens at the end of each request, but
contexts may be pushed manually during testing.
.. code-block:: python
with app.test_request_context():
...
When the ``with`` block exits (or ``ctx.pop()`` is called), the
teardown functions are called just before the request context is
made inactive.
When a teardown function was called because of an unhandled
exception it will be passed an error object. If an
:meth:`errorhandler` is registered, it will handle the exception
and the teardown will not receive it.
Teardown functions must avoid raising exceptions. If they
execute code that might fail they must surround that code with a
``try``/``except`` block and log any errors.
The return values of teardown functions are ignored.
This is available on both app and blueprint objects. When used on an app, this
executes after every request. When used on a blueprint, this executes after
every request that the blueprint handles. To register with a blueprint and
execute after every request, use :meth:`.Blueprint.teardown_app_request`.
"""
self.teardown_request_funcs.setdefault(None, []).append(f)
return f
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does teardown_request() do?
teardown_request() is a function in the flask codebase, defined in src/flask/sansio/scaffold.py.
Where is teardown_request() defined?
teardown_request() is defined in src/flask/sansio/scaffold.py at line 508.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free