Home / Function/ __init__() — flask Function Reference

__init__() — flask Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  31e318e5_adf8_900b_d893_adb4ea07a9b9["__init__()"]
  86817dcd_97b5_9a9f_aee8_5fa78b4cecc9["AppContext"]
  31e318e5_adf8_900b_d893_adb4ea07a9b9 -->|defined in| 86817dcd_97b5_9a9f_aee8_5fa78b4cecc9
  50282238_729d_4729_21d4_c290921ffa61["create_url_adapter()"]
  31e318e5_adf8_900b_d893_adb4ea07a9b9 -->|calls| 50282238_729d_4729_21d4_c290921ffa61
  style 31e318e5_adf8_900b_d893_adb4ea07a9b9 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

src/flask/ctx.py lines 299–336

    def __init__(
        self,
        app: Flask,
        *,
        request: Request | None = None,
        session: SessionMixin | None = None,
    ) -> None:
        self.app = app
        """The application represented by this context. Accessed through
        :data:`.current_app`.
        """

        self.g: _AppCtxGlobals = app.app_ctx_globals_class()
        """The global data for this context. Accessed through :data:`.g`."""

        self.url_adapter: MapAdapter | None = None
        """The URL adapter bound to the request, or the app if not in a request.
        May be ``None`` if binding failed.
        """

        self._request: Request | None = request
        self._session: SessionMixin | None = session
        self._flashes: list[tuple[str, str]] | None = None
        self._after_request_functions: list[ft.AfterRequestCallable[t.Any]] = []

        try:
            self.url_adapter = app.create_url_adapter(self._request)
        except HTTPException as e:
            if self._request is not None:
                self._request.routing_exception = e

        self._cv_token: contextvars.Token[AppContext] | None = None
        """The previous state to restore when popping."""

        self._push_count: int = 0
        """Track nested pushes of this context. Cleanup will only run once the
        original push has been popped.
        """

Subdomains

Defined In

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free