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 ~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 ~flask.blueprints.BlueprintSetupState
when the blueprint is registered on an application.
See :doc:`/blueprints` for more information.
Parameters | |
name | The name of the blueprint. Will be prepended to each endpoint name. |
import_name | The name of the blueprint package, usually __name__. This helps locate the root_path for the blueprint. |
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. |
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. |
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. |
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. |
subdomain | A subdomain that blueprint routes will match on by default. |
url_defaults | A dict of default values that blueprint routes will receive by default. |
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. |
Method | __init__ |
Undocumented |
Method | _is_setup_finished |
Undocumented |
Method | add_app_template_filter |
Register a custom template filter, available application wide. Like Flask.add_template_filter but for a blueprint. Works exactly like the app_template_filter decorator. |
Method | add_app_template_global |
Register a custom template global, available application wide. Like Flask.add_template_global but for a blueprint. Works exactly like the app_template_global decorator. |
Method | add_app_template_test |
Register a custom template test, available application wide. Like Flask.add_template_test but for a blueprint. Works exactly like the app_template_test decorator. |
Method | add_url_rule |
Like Flask.add_url_rule but for a blueprint. The endpoint for the url_for function is prefixed with the name of the blueprint. |
Method | after_app_request |
Like Flask.after_request but for a blueprint. Such a function is executed after each request, even if outside of the blueprint. |
Method | app_context_processor |
Like Flask.context_processor but for a blueprint. Such a function is executed each request, even if outside of the blueprint. |
Method | app_errorhandler |
Like Flask.errorhandler but for a blueprint. This handler is used for all requests, even if outside of the blueprint. |
Method | app_template_filter |
Register a custom template filter, available application wide. Like Flask.template_filter but for a blueprint. |
Method | app_template_global |
Register a custom template global, available application wide. Like Flask.template_global but for a blueprint. |
Method | app_template_test |
Register a custom template test, available application wide. Like Flask.template_test but for a blueprint. |
Method | app_url_defaults |
Same as url_defaults but application wide. |
Method | app_url_value_preprocessor |
Same as url_value_preprocessor but application wide. |
Method | before_app_first_request |
Like Flask.before_first_request . Such a function is executed before the first request to the application. |
Method | before_app_request |
Like Flask.before_request . Such a function is executed before each request, even if outside of a blueprint. |
Method | make_setup_state |
Creates an instance of ~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 |
No summary |
Method | record_once |
No summary |
Method | register |
No summary |
Method | register_blueprint |
Register a ~flask.Blueprint on this blueprint. Keyword arguments passed to this method will override the defaults set on the blueprint. |
Method | teardown_app_request |
Like Flask.teardown_request but for a blueprint. Such a function is executed when tearing down each request, even if outside of the blueprint. |
Class Variable | json_decoder |
Undocumented |
Class Variable | json_encoder |
Undocumented |
Class Variable | warn_on_modifications |
Undocumented |
Instance Variable | _blueprints |
Undocumented |
Instance Variable | _got_registered_once |
Undocumented |
Instance Variable | cli_group |
Undocumented |
Instance Variable | deferred_functions |
Undocumented |
Instance Variable | name |
Undocumented |
Instance Variable | subdomain |
Undocumented |
Instance Variable | url_prefix |
Undocumented |
Instance Variable | url_values_defaults |
Undocumented |
Inherited from Scaffold
:
Static Method | _get_exc_class_and_code |
Get the exception class being handled. For HTTP status codes or HTTPException subclasses, return both the exception and status code. |
Method | __repr__ |
Undocumented |
Method | _method_route |
Undocumented |
Method | after_request |
Register a function to run after each request to this object. |
Method | before_request |
Register a function to run before each request. |
Method | context_processor |
Registers a template context processor function. |
Method | delete |
Shortcut for 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 add_url_rule . |
Method | errorhandler |
Register a function to handle errors by code or exception class. |
Method | get |
Shortcut for route with methods=["GET"]. |
Method | get_send_file_max_age |
Used by send_file to determine the max_age cache value for a given file path if it wasn't passed. |
Method | open_resource |
Open a resource file relative to root_path for reading. |
Method | patch |
Shortcut for route with methods=["PATCH"]. |
Method | post |
Shortcut for route with methods=["POST"]. |
Method | put |
Shortcut for route with methods=["PUT"]. |
Method | register_error_handler |
Alternative error attach function to the 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 add_url_rule , which has more details about the implementation. |
Method | send_static_file |
No summary |
Method | static_folder.setter |
Undocumented |
Method | static_url_path.setter |
Undocumented |
Method | teardown_request |
No summary |
Method | url_defaults |
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_value_preprocessor |
Register a URL value preprocessor function for all view functions in the application. These functions will be called before the before_request functions. |
Instance Variable | _static_folder |
Undocumented |
Instance Variable | _static_url_path |
Undocumented |
Instance Variable | after_request_funcs |
Undocumented |
Instance Variable | before_request_funcs |
Undocumented |
Instance Variable | cli |
Undocumented |
Instance Variable | error_handler_spec |
Undocumented |
Instance Variable | import_name |
Undocumented |
Instance Variable | root_path |
Undocumented |
Instance Variable | teardown_request_funcs |
Undocumented |
Instance Variable | template_context_processors |
Undocumented |
Instance Variable | template_folder |
Undocumented |
Instance Variable | url_default_functions |
Undocumented |
Instance Variable | url_value_preprocessors |
Undocumented |
Instance Variable | view_functions |
Undocumented |
Property | has_static_folder |
True if static_folder is set. |
Property | jinja_loader |
The Jinja loader for this object's templates. By default this is a class jinja2.loaders.FileSystemLoader to template_folder if it is set. |
Property | static_folder |
The absolute path to the configured static folder. None if no static folder is set. |
Property | static_url_path |
The URL prefix that the static route will be accessible from. |
flask.scaffold.Scaffold.__init__
Undocumented
Parameters | |
name:str | Undocumented |
import_name:str | Undocumented |
static_folder:t.Optional[ | Undocumented |
static_url_path:t.Optional[ | Undocumented |
template_folder:t.Optional[ | Undocumented |
url_prefix:t.Optional[ | Undocumented |
subdomain:t.Optional[ | Undocumented |
url_defaults:t.Optional[ | Undocumented |
root_path:t.Optional[ | Undocumented |
cli_group:t.Optional[ | Undocumented |
Flask.add_template_filter
but for a blueprint. Works exactly
like the app_template_filter
decorator.Parameters | |
f:TemplateFilterCallable | Undocumented |
name:t.Optional[ | the optional name of the filter, otherwise the function name will be used. |
Register a custom template global, available application wide. Like
Flask.add_template_global
but for a blueprint. Works exactly
like the app_template_global
decorator.
Parameters | |
f:TemplateGlobalCallable | Undocumented |
name:t.Optional[ | the optional name of the global, otherwise the function name will be used. |
Register a custom template test, available application wide. Like
Flask.add_template_test
but for a blueprint. Works exactly
like the app_template_test
decorator.
Parameters | |
f:TemplateTestCallable | Undocumented |
name:t.Optional[ | the optional name of the test, otherwise the function name will be used. |
flask.scaffold.Scaffold.add_url_rule
Flask.add_url_rule
but for a blueprint. The endpoint for
the url_for
function is prefixed with the name of the blueprint.Parameters | |
rule:str | Undocumented |
endpoint:t.Optional[ | Undocumented |
view_func:t.Optional[ | Undocumented |
provide_automatic_options:t.Optional[ | Undocumented |
**options:t.Any | Undocumented |
Flask.after_request
but for a blueprint. Such a function
is executed after each request, even if outside of the blueprint.Parameters | |
f:AfterRequestCallable | Undocumented |
Returns | |
AfterRequestCallable | Undocumented |
Flask.context_processor
but for a blueprint. Such a
function is executed each request, even if outside of the blueprint.Parameters | |
f:TemplateContextProcessorCallable | Undocumented |
Returns | |
TemplateContextProcessorCallable | Undocumented |
Flask.errorhandler
but for a blueprint. This
handler is used for all requests, even if outside of the blueprint.Parameters | |
code:t.Union[ | Undocumented |
Returns | |
t.Callable | Undocumented |
Flask.template_filter
but for a blueprint.Parameters | |
name:t.Optional[ | the optional name of the filter, otherwise the function name will be used. |
Returns | |
t.Callable[ | Undocumented |
Register a custom template global, available application wide. Like
Flask.template_global
but for a blueprint.
Parameters | |
name:t.Optional[ | the optional name of the global, otherwise the function name will be used. |
Returns | |
t.Callable[ | Undocumented |
Register a custom template test, available application wide. Like
Flask.template_test
but for a blueprint.
Parameters | |
name:t.Optional[ | the optional name of the test, otherwise the function name will be used. |
Returns | |
t.Callable[ | Undocumented |
url_defaults
but application wide.Parameters | |
f:URLDefaultCallable | Undocumented |
Returns | |
URLDefaultCallable | Undocumented |
url_value_preprocessor
but application wide.Parameters | |
f:URLValuePreprocessorCallable | Undocumented |
Returns | |
URLValuePreprocessorCallable | Undocumented |
Flask.before_first_request
. Such a function is
executed before the first request to the application.Parameters | |
f:BeforeFirstRequestCallable | Undocumented |
Returns | |
BeforeFirstRequestCallable | Undocumented |
Flask.before_request
. Such a function is executed
before each request, even if outside of a blueprint.Parameters | |
f:BeforeRequestCallable | Undocumented |
Returns | |
BeforeRequestCallable | Undocumented |
~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.Parameters | |
app:Flask | Undocumented |
options:dict | Undocumented |
first_registration:bool | Undocumented |
Returns | |
BlueprintSetupState | Undocumented |
make_setup_state
method.Parameters | |
func:t.Callable | Undocumented |
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.Parameters | |
func:t.Callable | Undocumented |
Called by Flask.register_blueprint
to register all
views and callbacks registered on the blueprint with the
application. Creates a .BlueprintSetupState
and calls
each record
callback with it.
Parameters | |
app:Flask | The application this blueprint is being registered with. |
options:dict | Keyword arguments forwarded from
~Flask.register_blueprint . |
Register a ~flask.Blueprint
on this blueprint. Keyword
arguments passed to this method will override the defaults set
on the blueprint.
Parameters | |
blueprint:Blueprint | Undocumented |
**options:t.Any | Undocumented |
Flask.teardown_request
but for a blueprint. Such a
function is executed when tearing down each request, even if outside of
the blueprint.Parameters | |
f:TeardownCallable | Undocumented |
Returns | |
TeardownCallable | Undocumented |