Home / Function/ has_app_context() — flask Function Reference

has_app_context() — flask Function Reference

Architecture documentation for the has_app_context() function in ctx.py from the flask codebase.

Entity Profile

Dependency Diagram

graph TD
  cf135ef0_3c35_dafc_14ea_3e666ed9f351["has_app_context()"]
  49f8280b_d7dc_110c_b848_8e7e56bfb19b["ctx.py"]
  cf135ef0_3c35_dafc_14ea_3e666ed9f351 -->|defined in| 49f8280b_d7dc_110c_b848_8e7e56bfb19b
  c1644887_6834_cf5b_9551_6a1aa07a77d7["get()"]
  cf135ef0_3c35_dafc_14ea_3e666ed9f351 -->|calls| c1644887_6834_cf5b_9551_6a1aa07a77d7
  style cf135ef0_3c35_dafc_14ea_3e666ed9f351 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

src/flask/ctx.py lines 234–256

def has_app_context() -> bool:
    """Test if an app context is active. Unlike :func:`has_request_context`
    this can be true outside a request, such as in a CLI command.

    .. code-block:: python

        from flask import has_app_context, g

        if has_app_context():
            g.cached_data = ...

    If an app context is active, the :data:`.g` and :data:`.current_app` context
    proxies will available and ``True``, otherwise ``False``. You can use that
    to test the data you use, rather than using this function.

        from flask import g

        if g:
            g.cached_data = ...

    .. versionadded:: 0.9
    """
    return _cv_app.get(None) is not None

Subdomains

Defined In

Calls

Frequently Asked Questions

What does has_app_context() do?
has_app_context() is a function in the flask codebase, defined in src/flask/ctx.py.
Where is has_app_context() defined?
has_app_context() is defined in src/flask/ctx.py at line 234.
What does has_app_context() call?
has_app_context() calls 1 function(s): get.

Analyze Your Own Codebase

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

Try Supermodel Free