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
  0c59fa87_9a90_f011_4207_98ae96479921["Blueprint"]
  a813bd5c_bf41_d926_8dde_6a113d5e0018["Scaffold"]
  0c59fa87_9a90_f011_4207_98ae96479921 -->|extends| a813bd5c_bf41_d926_8dde_6a113d5e0018
  758a865d_0775_4c38_5582_499379448d06["blueprints.py"]
  0c59fa87_9a90_f011_4207_98ae96479921 -->|defined in| 758a865d_0775_4c38_5582_499379448d06
  91246758_fc03_2cf8_40ae_7a5b56add5d7["__init__()"]
  0c59fa87_9a90_f011_4207_98ae96479921 -->|method| 91246758_fc03_2cf8_40ae_7a5b56add5d7
  e57c76c6_89ad_7170_19d3_fd0f86c99e64["_check_setup_finished()"]
  0c59fa87_9a90_f011_4207_98ae96479921 -->|method| e57c76c6_89ad_7170_19d3_fd0f86c99e64
  0b82c064_d082_834e_b86a_ea458a961988["record()"]
  0c59fa87_9a90_f011_4207_98ae96479921 -->|method| 0b82c064_d082_834e_b86a_ea458a961988
  0085606d_b5d3_d0dc_0155_6135d079c059["record_once()"]
  0c59fa87_9a90_f011_4207_98ae96479921 -->|method| 0085606d_b5d3_d0dc_0155_6135d079c059
  332767b5_f33c_7d07_a9d2_9d9efe7f8c22["make_setup_state()"]
  0c59fa87_9a90_f011_4207_98ae96479921 -->|method| 332767b5_f33c_7d07_a9d2_9d9efe7f8c22
  fed3f3dd_fb9c_9cc0_fcd6_bb40208b8981["register_blueprint()"]
  0c59fa87_9a90_f011_4207_98ae96479921 -->|method| fed3f3dd_fb9c_9cc0_fcd6_bb40208b8981
  ab08d213_c111_86c1_e5b9_dd3fd7770d86["register()"]
  0c59fa87_9a90_f011_4207_98ae96479921 -->|method| ab08d213_c111_86c1_e5b9_dd3fd7770d86
  fcb19d5b_9453_b002_936c_db0309530b8c["_merge_blueprint_funcs()"]
  0c59fa87_9a90_f011_4207_98ae96479921 -->|method| fcb19d5b_9453_b002_936c_db0309530b8c
  674e773f_4d02_61b4_8703_b931fcae73d7["add_url_rule()"]
  0c59fa87_9a90_f011_4207_98ae96479921 -->|method| 674e773f_4d02_61b4_8703_b931fcae73d7
  4c021390_c775_df56_939c_c01853bde95a["app_template_filter()"]
  0c59fa87_9a90_f011_4207_98ae96479921 -->|method| 4c021390_c775_df56_939c_c01853bde95a
  0e94cea7_d7a3_238f_715d_5d59f6552fb2["add_app_template_filter()"]
  0c59fa87_9a90_f011_4207_98ae96479921 -->|method| 0e94cea7_d7a3_238f_715d_5d59f6552fb2
  6d40b5cc_a5e0_8bf9_3d39_282523ec52cb["app_template_test()"]
  0c59fa87_9a90_f011_4207_98ae96479921 -->|method| 6d40b5cc_a5e0_8bf9_3d39_282523ec52cb

Relationship Graph

Source Code

src/flask/sansio/blueprints.py lines 119–692

class Blueprint(Scaffold):
    """Represents a blueprint, a collection of routes and other
    app-related functions that can be registered on a real application
    later.

    A blueprint is an object that allows defining application functions
    without requiring an application object ahead of time. It uses the
    same decorators as :class:`~flask.Flask`, but defers the need for an
    application by recording them for later registration.

    Decorating a function with a blueprint creates a deferred function
    that is called with :class:`~flask.blueprints.BlueprintSetupState`
    when the blueprint is registered on an application.

    See :doc:`/blueprints` for more information.

    :param name: The name of the blueprint. Will be prepended to each
        endpoint name.
    :param import_name: The name of the blueprint package, usually
        ``__name__``. This helps locate the ``root_path`` for the
        blueprint.
    :param static_folder: A folder with static files that should be
        served by the blueprint's static route. The path is relative to
        the blueprint's root path. Blueprint static files are disabled
        by default.
    :param static_url_path: The url to serve static files from.
        Defaults to ``static_folder``. If the blueprint does not have
        a ``url_prefix``, the app's static route will take precedence,
        and the blueprint's static files won't be accessible.
    :param template_folder: A folder with templates that should be added
        to the app's template search path. The path is relative to the
        blueprint's root path. Blueprint templates are disabled by
        default. Blueprint templates have a lower precedence than those
        in the app's templates folder.
    :param url_prefix: A path to prepend to all of the blueprint's URLs,
        to make them distinct from the rest of the app's routes.
    :param subdomain: A subdomain that blueprint routes will match on by
        default.
    :param url_defaults: A dict of default values that blueprint routes
        will receive by default.
    :param root_path: By default, the blueprint will automatically set
        this based on ``import_name``. In certain situations this
        automatic detection can fail, so the path can be specified
        manually instead.

    .. versionchanged:: 1.1.0
        Blueprints have a ``cli`` group to register nested CLI commands.
        The ``cli_group`` parameter controls the name of the group under
        the ``flask`` command.

    .. versionadded:: 0.7
    """

    _got_registered_once = False

    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[assignment]
    ):
        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 not name:
            raise ValueError("'name' may not be empty.")

        if "." in name:
            raise ValueError("'name' may not contain a dot '.' character.")

Extends

Frequently Asked Questions

What is the Blueprint class?
Blueprint is a class in the flask codebase, defined in src/flask/sansio/blueprints.py.
Where is Blueprint defined?
Blueprint is defined in src/flask/sansio/blueprints.py at line 119.
What does Blueprint extend?
Blueprint extends Scaffold.

Analyze Your Own Codebase

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

Try Supermodel Free