Home / Function/ has_request_context() — flask Function Reference

has_request_context() — flask Function Reference

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

Entity Profile

Dependency Diagram

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

Relationship Graph

Source Code

src/flask/ctx.py lines 208–231

def has_request_context() -> bool:
    """Test if an app context is active and if it has request information.

    .. code-block:: python

        from flask import has_request_context, request

        if has_request_context():
            remote_addr = request.remote_addr

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

    .. code-block:: python

        from flask import request

        if request:
            remote_addr = request.remote_addr

    .. versionadded:: 0.7
    """
    return (ctx := _cv_app.get(None)) is not None and ctx.has_request

Subdomains

Defined In

Calls

Frequently Asked Questions

What does has_request_context() do?
has_request_context() is a function in the flask codebase, defined in src/flask/ctx.py.
Where is has_request_context() defined?
has_request_context() is defined in src/flask/ctx.py at line 208.
What does has_request_context() call?
has_request_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