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
Method | __init__ |
Undocumented |
Method | add |
Register a template filter, available in any template rendered by the application. Works like the :meth:`app_template_filter` decorator. Equivalent to :meth:`.Flask.add_template_filter`. |
Method | add |
Register a template global, available in any template rendered by the application. Works like the :meth:`app_template_global` decorator. Equivalent to :meth:`.Flask.add_template_global`. |
Method | add |
Register a template test, available in any template rendered by the application. Works like the :meth:`app_template_test` decorator. Equivalent to :meth:`.Flask.add_template_test`. |
Method | add |
Register a URL rule with the blueprint. See :meth:`.Flask.add_url_rule` for full documentation. |
Method | after |
Like :meth:`after_request`, but after every request, not only those handled by the blueprint. Equivalent to :meth:`.Flask.after_request`. |
Method | app |
Like :meth:`context_processor`, but for templates rendered by every view, not only by the blueprint. Equivalent to :meth:`.Flask.context_processor`. |
Method | app |
Like :meth:`errorhandler`, but for every request, not only those handled by the blueprint. Equivalent to :meth:`.Flask.errorhandler`. |
Method | app |
Register a template filter, available in any template rendered by the application. Equivalent to :meth:`.Flask.template_filter`. |
Method | app |
Register a template global, available in any template rendered by the application. Equivalent to :meth:`.Flask.template_global`. |
Method | app |
Register a template test, available in any template rendered by the application. Equivalent to :meth:`.Flask.template_test`. |
Method | app |
Like :meth:`url_defaults`, but for every request, not only those handled by the blueprint. Equivalent to :meth:`.Flask.url_defaults`. |
Method | app |
Like :meth:`url_value_preprocessor`, but for every request, not only those handled by the blueprint. Equivalent to :meth:`.Flask.url_value_preprocessor`. |
Method | before |
Register a function to run before the first request to the application is handled by the worker. Equivalent to :meth:`.Flask.before_first_request`. |
Method | before |
Like :meth:`before_request`, but before every request, not only those handled by the blueprint. Equivalent to :meth:`.Flask.before_request`. |
Method | json |
Undocumented |
Method | json |
Undocumented |
Method | make |
Creates an instance of :meth:`~flask.blueprints.BlueprintSetupState` object that is later passed to the register callback functions. Subclasses can override this to return a subclass of the setup state. |
Method | record |
Registers a function that is called when the blueprint is registered on the application. This function is called with the state as argument as returned by the :meth:`make_setup_state` method. |
Method | record |
Works like :meth:`record` but wraps the function in another function that will ensure the function is only called once. If the blueprint is registered a second time on the application, the function passed is not called. |
Method | register |
Called by :meth:`Flask.register_blueprint` to register all views and callbacks registered on the blueprint with the application. Creates a :class:`.BlueprintSetupState` and calls each :meth:`record` callback with it. |
Method | register |
Register a :class:`~flask.Blueprint` on this blueprint. Keyword arguments passed to this method will override the defaults set on the blueprint. |
Method | teardown |
Like :meth:`teardown_request`, but after every request, not only those handled by the blueprint. Equivalent to :meth:`.Flask.teardown_request`. |
Instance Variable | cli |
Undocumented |
Instance Variable | deferred |
Undocumented |
Instance Variable | name |
Undocumented |
Instance Variable | subdomain |
Undocumented |
Instance Variable | url |
Undocumented |
Instance Variable | url |
Undocumented |
Property | json |
Blueprint-local JSON decoder class to use. Set to ``None`` to use the app's. |
Property | json |
Blueprint-local JSON encoder class to use. Set to ``None`` to use the app's. |
Method | _check |
Undocumented |
Instance Variable | _blueprints |
Undocumented |
Instance Variable | _got |
Undocumented |
Instance Variable | _json |
Undocumented |
Instance Variable | _json |
Undocumented |
Inherited from Scaffold
:
Method | __repr__ |
Undocumented |
Method | after |
Register a function to run after each request to this object. |
Method | before |
Register a function to run before each request. |
Method | context |
Registers a template context processor function. These functions run before rendering a template. The keys of the returned dict are added as variables available in the template. |
Method | delete |
Shortcut for :meth:`route` with ``methods=["DELETE"]``. |
Method | endpoint |
Decorate a view function to register it for the given endpoint. Used if a rule is added without a ``view_func`` with :meth:`add_url_rule`. |
Method | errorhandler |
Register a function to handle errors by code or exception class. |
Method | get |
Shortcut for :meth:`route` with ``methods=["GET"]``. |
Method | get |
Used by :func:`send_file` to determine the ``max_age`` cache value for a given file path if it wasn't passed. |
Method | open |
Open a resource file relative to :attr:`root_path` for reading. |
Method | patch |
Shortcut for :meth:`route` with ``methods=["PATCH"]``. |
Method | post |
Shortcut for :meth:`route` with ``methods=["POST"]``. |
Method | put |
Shortcut for :meth:`route` with ``methods=["PUT"]``. |
Method | register |
Alternative error attach function to the :meth:`errorhandler` decorator that is more straightforward to use for non decorator usage. |
Method | route |
Decorate a view function to register it with the given URL rule and options. Calls :meth:`add_url_rule`, which has more details about the implementation. |
Method | send |
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. |
Method | static |
Undocumented |
Method | static |
Undocumented |
Method | teardown |
Register a function to be called when the request context is popped. Typically this happens at the end of each request, but contexts may be pushed manually as well during testing. |
Method | url |
Callback function for URL defaults for all view functions of the application. It's called with the endpoint and values and should update the values passed in place. |
Method | url |
Register a URL value preprocessor function for all view functions in the application. These functions will be called before the :meth:`before_request` functions. |
Instance Variable | after |
Undocumented |
Instance Variable | before |
Undocumented |
Instance Variable | cli |
Undocumented |
Instance Variable | error |
Undocumented |
Instance Variable | import |
Undocumented |
Instance Variable | root |
Undocumented |
Instance Variable | teardown |
Undocumented |
Instance Variable | template |
Undocumented |
Instance Variable | template |
Undocumented |
Instance Variable | url |
Undocumented |
Instance Variable | url |
Undocumented |
Instance Variable | view |
Undocumented |
Property | has |
``True`` if :attr:`static_folder` is set. |
Property | jinja |
The Jinja loader for this object's templates. By default this is a class :class:`jinja2.loaders.FileSystemLoader` to :attr:`template_folder` if it is set. |
Property | static |
The absolute path to the configured static folder. ``None`` if no static folder is set. |
Property | static |
The URL prefix that the static route will be accessible from. |
Static Method | _get |
Get the exception class being handled. For HTTP status codes or ``HTTPException`` subclasses, return both the exception and status code. |
Method | _method |
Undocumented |
Instance Variable | _static |
Undocumented |
Instance Variable | _static |
Undocumented |
str
, import_name: str
, static_folder: t.Optional[ t.Union[ str, os.PathLike]]
= None, static_url_path: t.Optional[ str]
= None, template_folder: t.Optional[ t.Union[ str, os.PathLike]]
= None, url_prefix: t.Optional[ str]
= None, subdomain: t.Optional[ str]
= None, url_defaults: t.Optional[ dict]
= None, root_path: t.Optional[ str]
= None, cli_group: t.Optional[ str]
= _sentinel):
(source)
¶
flask.scaffold.Scaffold.__init__
Undocumented
def add_app_template_filter(self, f:
ft.TemplateFilterCallable
, name: t.Optional[ str]
= None):
(source)
¶
Register a template filter, available in any template rendered by the application. Works like the :meth:`app_template_filter` decorator. Equivalent to :meth:`.Flask.add_template_filter`. :param name: the optional name of the filter, otherwise the function name will be used.
def add_app_template_global(self, f:
ft.TemplateGlobalCallable
, name: t.Optional[ str]
= None):
(source)
¶
Register a template global, available in any template rendered by the application. Works like the :meth:`app_template_global` decorator. Equivalent to :meth:`.Flask.add_template_global`. .. versionadded:: 0.10 :param name: the optional name of the global, otherwise the function name will be used.
def add_app_template_test(self, f:
ft.TemplateTestCallable
, name: t.Optional[ str]
= None):
(source)
¶
Register a template test, available in any template rendered by the application. Works like the :meth:`app_template_test` decorator. Equivalent to :meth:`.Flask.add_template_test`. .. versionadded:: 0.10 :param name: the optional name of the test, otherwise the function name will be used.
def add_url_rule(self, rule:
str
, endpoint: t.Optional[ str]
= None, view_func: t.Optional[ ft.RouteCallable]
= None, provide_automatic_options: t.Optional[ bool]
= None, **options: t.Any
):
(source)
¶
flask.scaffold.Scaffold.add_url_rule
Register a URL rule with the blueprint. See :meth:`.Flask.add_url_rule` for full documentation. The URL rule is prefixed with the blueprint's URL prefix. The endpoint name, used with :func:`url_for`, is prefixed with the blueprint's name.
Like :meth:`after_request`, but after every request, not only those handled by the blueprint. Equivalent to :meth:`.Flask.after_request`.
def app_context_processor(self, f:
T_template_context_processor
) -> T_template_context_processor
:
(source)
¶
Like :meth:`context_processor`, but for templates rendered by every view, not only by the blueprint. Equivalent to :meth:`.Flask.context_processor`.
def app_errorhandler(self, code:
t.Union[ t.Type[ Exception], int]
) -> t.Callable[ [ T_error_handler], T_error_handler]
:
(source)
¶
Like :meth:`errorhandler`, but for every request, not only those handled by the blueprint. Equivalent to :meth:`.Flask.errorhandler`.
def app_template_filter(self, name:
t.Optional[ str]
= None) -> t.Callable[ [ T_template_filter], T_template_filter]
:
(source)
¶
Register a template filter, available in any template rendered by the application. Equivalent to :meth:`.Flask.template_filter`. :param name: the optional name of the filter, otherwise the function name will be used.
def app_template_global(self, name:
t.Optional[ str]
= None) -> t.Callable[ [ T_template_global], T_template_global]
:
(source)
¶
Register a template global, available in any template rendered by the application. Equivalent to :meth:`.Flask.template_global`. .. versionadded:: 0.10 :param name: the optional name of the global, otherwise the function name will be used.
def app_template_test(self, name:
t.Optional[ str]
= None) -> t.Callable[ [ T_template_test], T_template_test]
:
(source)
¶
Register a template test, available in any template rendered by the application. Equivalent to :meth:`.Flask.template_test`. .. versionadded:: 0.10 :param name: the optional name of the test, otherwise the function name will be used.
Like :meth:`url_defaults`, but for every request, not only those handled by the blueprint. Equivalent to :meth:`.Flask.url_defaults`.
def app_url_value_preprocessor(self, f:
T_url_value_preprocessor
) -> T_url_value_preprocessor
:
(source)
¶
Like :meth:`url_value_preprocessor`, but for every request, not only those handled by the blueprint. Equivalent to :meth:`.Flask.url_value_preprocessor`.
def before_app_first_request(self, f:
T_before_first_request
) -> T_before_first_request
:
(source)
¶
Register a function to run before the first request to the application is handled by the worker. Equivalent to :meth:`.Flask.before_first_request`. .. deprecated:: 2.2 Will be removed in Flask 2.3. Run setup code when creating the application instead.
Like :meth:`before_request`, but before every request, not only those handled by the blueprint. Equivalent to :meth:`.Flask.before_request`.
def json_decoder(self, value:
t.Union[ t.Type[ json.JSONDecoder], None]
):
(source)
¶
Undocumented
def json_encoder(self, value:
t.Union[ t.Type[ json.JSONEncoder], None]
):
(source)
¶
Undocumented
Flask
, options: dict
, first_registration: bool
= False) -> BlueprintSetupState
:
(source)
¶
Creates an instance of :meth:`~flask.blueprints.BlueprintSetupState` object that is later passed to the register callback functions. Subclasses can override this to return a subclass of the setup state.
Registers a function that is called when the blueprint is registered on the application. This function is called with the state as argument as returned by the :meth:`make_setup_state` method.
Works like :meth:`record` but wraps the function in another function that will ensure the function is only called once. If the blueprint is registered a second time on the application, the function passed is not called.
Called by :meth:`Flask.register_blueprint` to register all views and callbacks registered on the blueprint with the application. Creates a :class:`.BlueprintSetupState` and calls each :meth:`record` callback with it. :param app: The application this blueprint is being registered with. :param options: Keyword arguments forwarded from :meth:`~Flask.register_blueprint`. .. versionchanged:: 2.0.1 Nested blueprints are registered with their dotted name. This allows different blueprints with the same name to be nested at different locations. .. versionchanged:: 2.0.1 The ``name`` option can be used to change the (pre-dotted) name the blueprint is registered with. This allows the same blueprint to be registered multiple times with unique names for ``url_for``. .. versionchanged:: 2.0.1 Registering the same blueprint with the same name multiple times is deprecated and will become an error in Flask 2.1.
Register a :class:`~flask.Blueprint` on this blueprint. Keyword arguments passed to this method will override the defaults set on the blueprint. .. versionchanged:: 2.0.1 The ``name`` option can be used to change the (pre-dotted) name the blueprint is registered with. This allows the same blueprint to be registered multiple times with unique names for ``url_for``. .. versionadded:: 2.0
Like :meth:`teardown_request`, but after every request, not only those handled by the blueprint. Equivalent to :meth:`.Flask.teardown_request`.
flask.scaffold.Scaffold.json_decoder
Blueprint-local JSON decoder class to use. Set to ``None`` to use the app's. .. deprecated:: 2.2 Will be removed in Flask 2.3. Customize :attr:`json_provider_class` instead. .. versionadded:: 0.10
flask.scaffold.Scaffold.json_encoder
Blueprint-local JSON encoder class to use. Set to ``None`` to use the app's. .. deprecated:: 2.2 Will be removed in Flask 2.3. Customize :attr:`json_provider_class` instead. .. versionadded:: 0.10