Home / Function/ __init__() — flask Function Reference

__init__() — flask Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  21993c25_d44a_bd35_e477_2d16af1e7237["__init__()"]
  9f8cc56e_d5c4_e7a8_438a_3124c0dd5de5["Flask"]
  21993c25_d44a_bd35_e477_2d16af1e7237 -->|defined in| 9f8cc56e_d5c4_e7a8_438a_3124c0dd5de5
  0961f519_f2ef_dd1b_2adf_c3eaabdb53a7["send_static_file()"]
  21993c25_d44a_bd35_e477_2d16af1e7237 -->|calls| 0961f519_f2ef_dd1b_2adf_c3eaabdb53a7
  style 21993c25_d44a_bd35_e477_2d16af1e7237 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

src/flask/app.py lines 309–362

    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,
    ):
        super().__init__(
            import_name=import_name,
            static_url_path=static_url_path,
            static_folder=static_folder,
            static_host=static_host,
            host_matching=host_matching,
            subdomain_matching=subdomain_matching,
            template_folder=template_folder,
            instance_path=instance_path,
            instance_relative_config=instance_relative_config,
            root_path=root_path,
        )

        #: The Click command group for registering CLI commands for this
        #: object. The commands are available from the ``flask`` command
        #: once the application has been discovered and blueprints have
        #: been registered.
        self.cli = cli.AppGroup()

        # Set the name of the Click group in case someone wants to add
        # the app's commands to another CLI tool.
        self.cli.name = self.name

        # Add a static route using the provided static_url_path, static_host,
        # and static_folder if there is a configured static_folder.
        # Note we do this without checking if static_folder exists.
        # For one, it might be created while the server is running (e.g. during
        # development). Also, Google App Engine stores static files somewhere
        if self.has_static_folder:
            assert bool(static_host) == host_matching, (
                "Invalid static_host/host_matching combination"
            )
            # Use a weakref to avoid creating a reference cycle between the app
            # and the view function (see #3761).
            self_ref = weakref.ref(self)
            self.add_url_rule(
                f"{self.static_url_path}/<path:filename>",
                endpoint="static",
                host=static_host,
                view_func=lambda **kw: self_ref().send_static_file(**kw),  # type: ignore
            )

Subdomains

Defined In

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free