App Class — flask Architecture
Architecture documentation for the App class in app.py from the flask codebase.
Entity Profile
Dependency Diagram
graph TD 38f6d4a2_834e_2acd_e1b6_f45c58079ccd["App"] a813bd5c_bf41_d926_8dde_6a113d5e0018["Scaffold"] 38f6d4a2_834e_2acd_e1b6_f45c58079ccd -->|extends| a813bd5c_bf41_d926_8dde_6a113d5e0018 ed6b5ded_713e_74a7_fd38_486c9303d21c["app.py"] 38f6d4a2_834e_2acd_e1b6_f45c58079ccd -->|defined in| ed6b5ded_713e_74a7_fd38_486c9303d21c 4b05301c_76b4_7bf6_5a71_e4588c1d623f["__init__()"] 38f6d4a2_834e_2acd_e1b6_f45c58079ccd -->|method| 4b05301c_76b4_7bf6_5a71_e4588c1d623f ac9f38b2_08ef_d9a4_1eb3_93e8392b3c9c["_check_setup_finished()"] 38f6d4a2_834e_2acd_e1b6_f45c58079ccd -->|method| ac9f38b2_08ef_d9a4_1eb3_93e8392b3c9c a69c4070_6705_508c_e8c3_a713102a2f63["name()"] 38f6d4a2_834e_2acd_e1b6_f45c58079ccd -->|method| a69c4070_6705_508c_e8c3_a713102a2f63 01bfe763_91d4_5986_a6e1_da306981acee["logger()"] 38f6d4a2_834e_2acd_e1b6_f45c58079ccd -->|method| 01bfe763_91d4_5986_a6e1_da306981acee b5727c4c_564c_6e3b_0ae8_dc9dd1e74cfb["jinja_env()"] 38f6d4a2_834e_2acd_e1b6_f45c58079ccd -->|method| b5727c4c_564c_6e3b_0ae8_dc9dd1e74cfb 1c5f5aa4_5c04_8aae_971c_720c698c8609["create_jinja_environment()"] 38f6d4a2_834e_2acd_e1b6_f45c58079ccd -->|method| 1c5f5aa4_5c04_8aae_971c_720c698c8609 908b035e_2774_0f2e_e247_003a3044450d["make_config()"] 38f6d4a2_834e_2acd_e1b6_f45c58079ccd -->|method| 908b035e_2774_0f2e_e247_003a3044450d ddf03535_deb9_49d0_f14d_3127a2c7daaa["make_aborter()"] 38f6d4a2_834e_2acd_e1b6_f45c58079ccd -->|method| ddf03535_deb9_49d0_f14d_3127a2c7daaa 5d914b38_d2af_c173_db31_3a2d1e8e567d["auto_find_instance_path()"] 38f6d4a2_834e_2acd_e1b6_f45c58079ccd -->|method| 5d914b38_d2af_c173_db31_3a2d1e8e567d 25995efa_e089_6027_3808_3fb8a1179de8["create_global_jinja_loader()"] 38f6d4a2_834e_2acd_e1b6_f45c58079ccd -->|method| 25995efa_e089_6027_3808_3fb8a1179de8 ba380111_3aea_0e4a_3cdc_c6b5aff05cf8["select_jinja_autoescape()"] 38f6d4a2_834e_2acd_e1b6_f45c58079ccd -->|method| ba380111_3aea_0e4a_3cdc_c6b5aff05cf8 a2acbfc3_d486_fd85_1cac_86e38627ed40["debug()"] 38f6d4a2_834e_2acd_e1b6_f45c58079ccd -->|method| a2acbfc3_d486_fd85_1cac_86e38627ed40
Relationship Graph
Source Code
src/flask/sansio/app.py lines 59–1010
class App(Scaffold):
"""The flask object implements a WSGI application and acts as the central
object. It is passed the name of the module or package of the
application. Once it is created it will act as a central registry for
the view functions, the URL rules, template configuration and much more.
The name of the package is used to resolve resources from inside the
package or the folder the module is contained in depending on if the
package parameter resolves to an actual python package (a folder with
an :file:`__init__.py` file inside) or a standard module (just a ``.py`` file).
For more information about resource loading, see :func:`open_resource`.
Usually you create a :class:`Flask` instance in your main module or
in the :file:`__init__.py` file of your package like this::
from flask import Flask
app = Flask(__name__)
.. admonition:: About the First Parameter
The idea of the first parameter is to give Flask an idea of what
belongs to your application. This name is used to find resources
on the filesystem, can be used by extensions to improve debugging
information and a lot more.
So it's important what you provide there. If you are using a single
module, `__name__` is always the correct value. If you however are
using a package, it's usually recommended to hardcode the name of
your package there.
For example if your application is defined in :file:`yourapplication/app.py`
you should create it with one of the two versions below::
app = Flask('yourapplication')
app = Flask(__name__.split('.')[0])
Why is that? The application will work even with `__name__`, thanks
to how resources are looked up. However it will make debugging more
painful. Certain extensions can make assumptions based on the
import name of your application. For example the Flask-SQLAlchemy
extension will look for the code in your application that triggered
an SQL query in debug mode. If the import name is not properly set
up, that debugging information is lost. (For example it would only
pick up SQL queries in `yourapplication.app` and not
`yourapplication.views.frontend`)
.. versionadded:: 0.7
The `static_url_path`, `static_folder`, and `template_folder`
parameters were added.
.. versionadded:: 0.8
The `instance_path` and `instance_relative_config` parameters were
added.
.. versionadded:: 0.11
The `root_path` parameter was added.
.. versionadded:: 1.0
The ``host_matching`` and ``static_host`` parameters were added.
.. versionadded:: 1.0
The ``subdomain_matching`` parameter was added. Subdomain
matching needs to be enabled manually now. Setting
:data:`SERVER_NAME` does not implicitly enable it.
:param import_name: the name of the application package
:param static_url_path: can be used to specify a different path for the
static files on the web. Defaults to the name
of the `static_folder` folder.
:param static_folder: The folder with static files that is served at
``static_url_path``. Relative to the application ``root_path``
or an absolute path. Defaults to ``'static'``.
:param static_host: the host to use when adding the static route.
Defaults to None. Required when using ``host_matching=True``
with a ``static_folder`` configured.
:param host_matching: set ``url_map.host_matching`` attribute.
Defaults to False.
:param subdomain_matching: consider the subdomain relative to
:data:`SERVER_NAME` when matching routes. Defaults to False.
:param template_folder: the folder that contains the templates that should
Domain
Defined In
Extends
Source
Frequently Asked Questions
What is the App class?
App is a class in the flask codebase, defined in src/flask/sansio/app.py.
Where is App defined?
App is defined in src/flask/sansio/app.py at line 59.
What does App extend?
App extends Scaffold.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free