Home / Class/ Blueprint Class — flask Architecture

Blueprint Class — flask Architecture

Architecture documentation for the Blueprint class in blueprints.py from the flask codebase.

Entity Profile

Dependency Diagram

graph TD
  43802377_8224_2289_2f49_1129adf043ee["Blueprint"]
  ebbad164_1651_bd83_3f3b_106e2ce78240["blueprints.py"]
  43802377_8224_2289_2f49_1129adf043ee -->|defined in| ebbad164_1651_bd83_3f3b_106e2ce78240
  a467deec_dbd2_7e8e_b9aa_7ad579be0b52["__init__()"]
  43802377_8224_2289_2f49_1129adf043ee -->|method| a467deec_dbd2_7e8e_b9aa_7ad579be0b52
  afe24c34_5566_a80f_fbff_bb57cec6d844["get_send_file_max_age()"]
  43802377_8224_2289_2f49_1129adf043ee -->|method| afe24c34_5566_a80f_fbff_bb57cec6d844
  4a852f3a_2bc8_50e9_493b_6ec8169d1a41["send_static_file()"]
  43802377_8224_2289_2f49_1129adf043ee -->|method| 4a852f3a_2bc8_50e9_493b_6ec8169d1a41
  08a1740c_dd5d_29d7_d959_c916e58e9e8c["open_resource()"]
  43802377_8224_2289_2f49_1129adf043ee -->|method| 08a1740c_dd5d_29d7_d959_c916e58e9e8c

Relationship Graph

Source Code

src/flask/blueprints.py lines 18–128

class Blueprint(SansioBlueprint):
    def __init__(
        self,
        name: str,
        import_name: str,
        static_folder: str | os.PathLike[str] | None = None,
        static_url_path: str | None = None,
        template_folder: str | os.PathLike[str] | None = None,
        url_prefix: str | None = None,
        subdomain: str | None = None,
        url_defaults: dict[str, t.Any] | None = None,
        root_path: str | None = None,
        cli_group: str | None = _sentinel,  # type: ignore
    ) -> None:
        super().__init__(
            name,
            import_name,
            static_folder,
            static_url_path,
            template_folder,
            url_prefix,
            subdomain,
            url_defaults,
            root_path,
            cli_group,
        )

        #: 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 = 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

    def get_send_file_max_age(self, filename: str | None) -> int | None:
        """Used by :func:`send_file` to determine the ``max_age`` cache
        value for a given file path if it wasn't passed.

        By default, this returns :data:`SEND_FILE_MAX_AGE_DEFAULT` from
        the configuration of :data:`~flask.current_app`. This defaults
        to ``None``, which tells the browser to use conditional requests
        instead of a timed cache, which is usually preferable.

        Note this is a duplicate of the same method in the Flask
        class.

        .. versionchanged:: 2.0
            The default configuration is ``None`` instead of 12 hours.

        .. versionadded:: 0.9
        """
        value = current_app.config["SEND_FILE_MAX_AGE_DEFAULT"]

        if value is None:
            return None

        if isinstance(value, timedelta):
            return int(value.total_seconds())

        return value  # type: ignore[no-any-return]

    def send_static_file(self, filename: str) -> Response:
        """The view function used to serve files from
        :attr:`static_folder`. A route is automatically registered for
        this view at :attr:`static_url_path` if :attr:`static_folder` is
        set.

        Note this is a duplicate of the same method in the Flask
        class.

        .. versionadded:: 0.5

        """
        if not self.has_static_folder:
            raise RuntimeError("'static_folder' must be set to serve static_files.")

        # send_file only knows to call get_send_file_max_age on the app,
        # call it here so it works for blueprints too.

Frequently Asked Questions

What is the Blueprint class?
Blueprint is a class in the flask codebase, defined in src/flask/blueprints.py.
Where is Blueprint defined?
Blueprint is defined in src/flask/blueprints.py at line 18.

Analyze Your Own Codebase

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

Try Supermodel Free