Home / Function/ with_appcontext() — flask Function Reference

with_appcontext() — flask Function Reference

Architecture documentation for the with_appcontext() function in cli.py from the flask codebase.

Entity Profile

Dependency Diagram

graph TD
  7a19d77a_86f4_0e30_0626_5cb2e17c7eae["with_appcontext()"]
  a96499c3_f8a9_e782_f156_1c1ee4a86c69["cli.py"]
  7a19d77a_86f4_0e30_0626_5cb2e17c7eae -->|defined in| a96499c3_f8a9_e782_f156_1c1ee4a86c69
  f688268e_280f_36e3_281d_55ae0a492f60["command()"]
  f688268e_280f_36e3_281d_55ae0a492f60 -->|calls| 7a19d77a_86f4_0e30_0626_5cb2e17c7eae
  6cabef6b_f1ce_76af_5916_c4e9a439548c["load_app()"]
  7a19d77a_86f4_0e30_0626_5cb2e17c7eae -->|calls| 6cabef6b_f1ce_76af_5916_c4e9a439548c
  92f86b9d_3382_d2d4_7d8f_03f683ac426b["app_context()"]
  7a19d77a_86f4_0e30_0626_5cb2e17c7eae -->|calls| 92f86b9d_3382_d2d4_7d8f_03f683ac426b
  style 7a19d77a_86f4_0e30_0626_5cb2e17c7eae fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

src/flask/cli.py lines 380–402

def with_appcontext(f: F) -> F:
    """Wraps a callback so that it's guaranteed to be executed with the
    script's application context.

    Custom commands (and their options) registered under ``app.cli`` or
    ``blueprint.cli`` will always have an app context available, this
    decorator is not required in that case.

    .. versionchanged:: 2.2
        The app context is active for subcommands as well as the
        decorated callback. The app context is always available to
        ``app.cli`` command and parameter callbacks.
    """

    @click.pass_context
    def decorator(ctx: click.Context, /, *args: t.Any, **kwargs: t.Any) -> t.Any:
        if not current_app:
            app = ctx.ensure_object(ScriptInfo).load_app()
            ctx.with_resource(app.app_context())

        return ctx.invoke(f, *args, **kwargs)

    return update_wrapper(decorator, f)  # type: ignore[return-value]

Subdomains

Defined In

Called By

Frequently Asked Questions

What does with_appcontext() do?
with_appcontext() is a function in the flask codebase, defined in src/flask/cli.py.
Where is with_appcontext() defined?
with_appcontext() is defined in src/flask/cli.py at line 380.
What does with_appcontext() call?
with_appcontext() calls 2 function(s): app_context, load_app.
What calls with_appcontext()?
with_appcontext() is called by 1 function(s): command.

Analyze Your Own Codebase

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

Try Supermodel Free