Home / Function/ teardown_appcontext() — flask Function Reference

teardown_appcontext() — flask Function Reference

Architecture documentation for the teardown_appcontext() function in app.py from the flask codebase.

Entity Profile

Dependency Diagram

graph TD
  6cbf5399_1973_3c2f_3bc4_1f3488d97432["teardown_appcontext()"]
  38f6d4a2_834e_2acd_e1b6_f45c58079ccd["App"]
  6cbf5399_1973_3c2f_3bc4_1f3488d97432 -->|defined in| 38f6d4a2_834e_2acd_e1b6_f45c58079ccd
  style 6cbf5399_1973_3c2f_3bc4_1f3488d97432 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

src/flask/sansio/app.py lines 824–852

    def teardown_appcontext(self, f: T_teardown) -> T_teardown:
        """Registers a function to be called when the app context is popped. The
        context is popped at the end of a request, CLI command, or manual ``with``
        block.

        .. code-block:: python

            with app.app_context():
                ...

        When the ``with`` block exits (or ``ctx.pop()`` is called), the
        teardown functions are called just before the app 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.

        .. versionadded:: 0.9
        """
        self.teardown_appcontext_funcs.append(f)
        return f

Subdomains

Frequently Asked Questions

What does teardown_appcontext() do?
teardown_appcontext() is a function in the flask codebase, defined in src/flask/sansio/app.py.
Where is teardown_appcontext() defined?
teardown_appcontext() is defined in src/flask/sansio/app.py at line 824.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free