__init__() — flask Function Reference
Architecture documentation for the __init__() function in app.py from the flask codebase.
Entity Profile
Dependency Diagram
graph TD 4b05301c_76b4_7bf6_5a71_e4588c1d623f["__init__()"] 38f6d4a2_834e_2acd_e1b6_f45c58079ccd["App"] 4b05301c_76b4_7bf6_5a71_e4588c1d623f -->|defined in| 38f6d4a2_834e_2acd_e1b6_f45c58079ccd 5d914b38_d2af_c173_db31_3a2d1e8e567d["auto_find_instance_path()"] 4b05301c_76b4_7bf6_5a71_e4588c1d623f -->|calls| 5d914b38_d2af_c173_db31_3a2d1e8e567d 908b035e_2774_0f2e_e247_003a3044450d["make_config()"] 4b05301c_76b4_7bf6_5a71_e4588c1d623f -->|calls| 908b035e_2774_0f2e_e247_003a3044450d ddf03535_deb9_49d0_f14d_3127a2c7daaa["make_aborter()"] 4b05301c_76b4_7bf6_5a71_e4588c1d623f -->|calls| ddf03535_deb9_49d0_f14d_3127a2c7daaa style 4b05301c_76b4_7bf6_5a71_e4588c1d623f fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
src/flask/sansio/app.py lines 279–408
def __init__(
self,
import_name: str,
static_url_path: str | None = None,
static_folder: str | os.PathLike[str] | None = "static",
static_host: str | None = None,
host_matching: bool = False,
subdomain_matching: bool = False,
template_folder: str | os.PathLike[str] | None = "templates",
instance_path: str | None = None,
instance_relative_config: bool = False,
root_path: str | None = None,
) -> None:
super().__init__(
import_name=import_name,
static_folder=static_folder,
static_url_path=static_url_path,
template_folder=template_folder,
root_path=root_path,
)
if instance_path is None:
instance_path = self.auto_find_instance_path()
elif not os.path.isabs(instance_path):
raise ValueError(
"If an instance path is provided it must be absolute."
" A relative path was given instead."
)
#: Holds the path to the instance folder.
#:
#: .. versionadded:: 0.8
self.instance_path = instance_path
#: The configuration dictionary as :class:`Config`. This behaves
#: exactly like a regular dictionary but supports additional methods
#: to load a config from files.
self.config = self.make_config(instance_relative_config)
#: An instance of :attr:`aborter_class` created by
#: :meth:`make_aborter`. This is called by :func:`flask.abort`
#: to raise HTTP errors, and can be called directly as well.
#:
#: .. versionadded:: 2.2
#: Moved from ``flask.abort``, which calls this object.
self.aborter = self.make_aborter()
self.json: JSONProvider = self.json_provider_class(self)
"""Provides access to JSON methods. Functions in ``flask.json``
will call methods on this provider when the application context
is active. Used for handling JSON requests and responses.
An instance of :attr:`json_provider_class`. Can be customized by
changing that attribute on a subclass, or by assigning to this
attribute afterwards.
The default, :class:`~flask.json.provider.DefaultJSONProvider`,
uses Python's built-in :mod:`json` library. A different provider
can use a different JSON library.
.. versionadded:: 2.2
"""
#: A list of functions that are called by
#: :meth:`handle_url_build_error` when :meth:`.url_for` raises a
#: :exc:`~werkzeug.routing.BuildError`. Each function is called
#: with ``error``, ``endpoint`` and ``values``. If a function
#: returns ``None`` or raises a ``BuildError``, it is skipped.
#: Otherwise, its return value is returned by ``url_for``.
#:
#: .. versionadded:: 0.9
self.url_build_error_handlers: list[
t.Callable[[Exception, str, dict[str, t.Any]], str]
] = []
#: A list of functions that are called when the application context
#: is destroyed. Since the application context is also torn down
#: if the request ends this is the place to store code that disconnects
#: from databases.
#:
#: .. versionadded:: 0.9
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does __init__() do?
__init__() is a function in the flask codebase, defined in src/flask/sansio/app.py.
Where is __init__() defined?
__init__() is defined in src/flask/sansio/app.py at line 279.
What does __init__() call?
__init__() calls 3 function(s): auto_find_instance_path, make_aborter, make_config.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free