Common behavior shared between :class:~flask.Flask and :class:~flask.blueprints.Blueprint.
Attributes
| Attribute | Type | Description |
|---|
| cli | Group | The Click command group for this object's CLI commands. |
| name | str | The name of the blueprint or application used for routing and endpoint names. |
Constructor
Signature
def Scaffold(
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,
root_path: str | None = None
) - > null
Parameters
| Name | Type | Description |
|---|
| import_name | str | The import name of the module where this object is defined. Usually name should be used. |
| static_folder | `str | os.PathLike[str] |
| static_url_path | `str | None` = None |
| template_folder | `str | os.PathLike[str] |
| root_path | `str | None` = None |
Methods
static_folder()
@classmethod
def static_folder() - > str | None
The absolute path to the configured static folder. None if no static folder is set.
Returns
has_static_folder()
@classmethod
def has_static_folder() - > bool
True if static_folder is set.
Returns
| Type | Description |
|---|
bool | A boolean indicating the presence of a configured static folder. |
static_url_path()
@classmethod
def static_url_path() - > str | None
The URL prefix that the static route will be accessible from.
Returns
jinja_loader()
@classmethod
def jinja_loader() - > BaseLoader | None
The Jinja loader for this object's templates. By default this is a class jinja2.loaders.FileSystemLoader to template_folder if it is set.
Returns
| Type | Description |
|---|
| `BaseLoader | None` |
get()
@classmethod
def get(
rule: str,
**options: t.Any
) - > t.Callable[[T_route], T_route]
Shortcut for route with methods=["GET"].
Parameters
| Name | Type | Description |
|---|
| rule | str | The URL rule string. |
| **options | t.Any | Extra options passed to the Rule object. |
Returns
| Type | Description |
|---|
t.Callable[[T_route], T_route] | A decorator to register a GET route. |
post()
@classmethod
def post(
rule: str,
**options: t.Any
) - > t.Callable[[T_route], T_route]
Shortcut for route with methods=["POST"].
Parameters
| Name | Type | Description |
|---|
| rule | str | The URL rule string. |
| **options | t.Any | Extra options passed to the Rule object. |
Returns
| Type | Description |
|---|
t.Callable[[T_route], T_route] | A decorator to register a POST route. |
put()
@classmethod
def put(
rule: str,
**options: t.Any
) - > t.Callable[[T_route], T_route]
Shortcut for route with methods=["PUT"].
Parameters
| Name | Type | Description |
|---|
| rule | str | The URL rule string. |
| **options | t.Any | Extra options passed to the Rule object. |
Returns
| Type | Description |
|---|
t.Callable[[T_route], T_route] | A decorator to register a PUT route. |
delete()
@classmethod
def delete(
rule: str,
**options: t.Any
) - > t.Callable[[T_route], T_route]
Shortcut for route with methods=["DELETE"].
Parameters
| Name | Type | Description |
|---|
| rule | str | The URL rule string. |
| **options | t.Any | Extra options passed to the Rule object. |
Returns
| Type | Description |
|---|
t.Callable[[T_route], T_route] | A decorator to register a DELETE route. |
patch()
@classmethod
def patch(
rule: str,
**options: t.Any
) - > t.Callable[[T_route], T_route]
Shortcut for route with methods=["PATCH"].
Parameters
| Name | Type | Description |
|---|
| rule | str | The URL rule string. |
| **options | t.Any | Extra options passed to the Rule object. |
Returns
| Type | Description |
|---|
t.Callable[[T_route], T_route] | A decorator to register a PATCH route. |
route()
@classmethod
def route(
rule: str,
**options: t.Any
) - > t.Callable[[T_route], T_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.
Parameters
| Name | Type | Description |
|---|
| rule | str | The URL rule string. |
| **options | t.Any | Extra options passed to the Rule object. |
Returns
| Type | Description |
|---|
t.Callable[[T_route], T_route] | A decorator that registers the function as a view for the given rule. |
add_url_rule()
@classmethod
def add_url_rule(
rule: str,
endpoint: str | None,
view_func: ft.RouteCallable | None,
provide_automatic_options: bool | None,
**options: t.Any
) - > None
Register a rule for routing incoming requests and building URLs. The route decorator is a shortcut to call this with the view_func argument.
Parameters
| Name | Type | Description |
|---|
| rule | str | The URL rule string. |
| endpoint | `str | None` |
| view_func | `ft.RouteCallable | None` |
| provide_automatic_options | `bool | None` |
| **options | t.Any | Extra options passed to the Rule object. |
Returns
endpoint()
@classmethod
def endpoint(
endpoint: str
) - > t.Callable[[F], F]
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.
Parameters
| Name | Type | Description |
|---|
| endpoint | str | The endpoint name to associate with the view function. |
Returns
| Type | Description |
|---|
t.Callable[[F], F] | A decorator that registers the function for the specified endpoint. |
before_request()
@classmethod
def before_request(
f: T_before_request
) - > T_before_request
Register a function to run before each request.
Parameters
| Name | Type | Description |
|---|
| f | T_before_request | The function to call before handling the request. |
Returns
| Type | Description |
|---|
T_before_request | The decorated function. |
after_request()
@classmethod
def after_request(
f: T_after_request
) - > T_after_request
Register a function to run after each request to this object.
Parameters
| Name | Type | Description |
|---|
| f | T_after_request | The function to call after handling the request, which must return a response. |
Returns
| Type | Description |
|---|
T_after_request | The decorated function. |
teardown_request()
@classmethod
def teardown_request(
f: T_teardown
) - > T_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 during testing.
Parameters
| Name | Type | Description |
|---|
| f | T_teardown | The function to call during request context teardown. |
Returns
| Type | Description |
|---|
T_teardown | The decorated function. |
context_processor()
@classmethod
def context_processor(
f: T_template_context_processor
) - > T_template_context_processor
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.
Parameters
| Name | Type | Description |
|---|
| f | T_template_context_processor | The function that returns a dictionary of variables for the template context. |
Returns
| Type | Description |
|---|
T_template_context_processor | The decorated function. |
url_value_preprocessor()
@classmethod
def url_value_preprocessor(
f: T_url_value_preprocessor
) - > T_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.
Parameters
| Name | Type | Description |
|---|
| f | T_url_value_preprocessor | The function to process URL values before they reach the view. |
Returns
| Type | Description |
|---|
T_url_value_preprocessor | The decorated function. |
url_defaults()
@classmethod
def url_defaults(
f: T_url_defaults
) - > T_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.
Parameters
| Name | Type | Description |
|---|
| f | T_url_defaults | The function to provide default values for URL generation. |
Returns
| Type | Description |
|---|
T_url_defaults | The decorated function. |
errorhandler()
@classmethod
def errorhandler(
code_or_exception: type[Exception]| int
) - > t.Callable[[T_error_handler], T_error_handler]
Register a function to handle errors by code or exception class.
Parameters
| Name | Type | Description |
|---|
| code_or_exception | `type[Exception] | int` |
Returns
| Type | Description |
|---|
t.Callable[[T_error_handler], T_error_handler] | A decorator to register the error handler function. |
register_error_handler()
@classmethod
def register_error_handler(
code_or_exception: type[Exception]| int,
f: ft.ErrorHandlerCallable
) - > None
Alternative error attach function to the errorhandler decorator that is more straightforward to use for non decorator usage.
Parameters
| Name | Type | Description |
|---|
| code_or_exception | `type[Exception] | int` |
| f | ft.ErrorHandlerCallable | The function to call when the error occurs. |
Returns