Common behavior shared between :class:~flask.Flask and :class:~flask.blueprints.Blueprint.
Attributes
| Attribute | Type | Description |
|---|
| cli | Group | This attribute stores a Group object, which is used for command-line interface functionalities. |
| name | str | This attribute stores a string representing the name of the object. |
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
Retrieves the absolute path to the configured static folder. This property allows access to the directory where static files (like CSS, JavaScript, images) are stored for serving.
Returns
static_folder()
@classmethod
def static_folder(
value: str | os.PathLike[str]| None
) - > None
Sets the static folder path for the Scaffold object. This allows configuring the directory from which static files will be served.
Parameters
| Name | Type | Description |
|---|
| value | `str | os.PathLike[str] |
Returns
| Type | Description |
|---|
None | This method does not return a value. |
has_static_folder()
@classmethod
def has_static_folder() - > bool
Checks if a static folder has been configured for the Scaffold object. This property is useful for determining if static file serving is enabled.
Returns
| Type | Description |
|---|
bool | "True" if a static folder is set, "False" otherwise. |
static_url_path()
@classmethod
def static_url_path() - > str | None
Retrieves the URL prefix under which static files will be accessible. This property determines the base URL for static assets.
Returns
static_url_path()
@classmethod
def static_url_path(
value: str | None
) - > None
Sets the URL prefix for static files. This allows customizing the base URL path for serving static assets.
Parameters
| Name | Type | Description |
|---|
| value | `str | None` |
Returns
| Type | Description |
|---|
None | This method does not return a value. |
jinja_loader()
@classmethod
def jinja_loader() - > BaseLoader | None
Retrieves the Jinja template loader configured for this object. This property provides access to the mechanism used to load templates for rendering.
Returns
| Type | Description |
|---|
| `BaseLoader | None` |
get()
@classmethod
def get(
rule: str,
options: t.Any
) - > t.Callable[[T_route], T_route]
Decorates a view function to register it for a GET request at the specified URL rule. This is a convenient shortcut for route() with methods=["GET"].
Parameters
| Name | Type | Description |
|---|
| rule | str | The URL rule string for the route. |
| options | t.Any | Extra options passed to the Werkzeug Rule object. |
Returns
| Type | Description |
|---|
t.Callable[[T_route], T_route] | A decorator that registers the view function for GET requests. |
post()
@classmethod
def post(
rule: str,
options: t.Any
) - > t.Callable[[T_route], T_route]
Decorates a view function to register it for a POST request at the specified URL rule. This is a convenient shortcut for route() with methods=["POST"].
Parameters
| Name | Type | Description |
|---|
| rule | str | The URL rule string for the route. |
| options | t.Any | Extra options passed to the Werkzeug Rule object. |
Returns
| Type | Description |
|---|
t.Callable[[T_route], T_route] | A decorator that registers the view function for POST requests. |
put()
@classmethod
def put(
rule: str,
options: t.Any
) - > t.Callable[[T_route], T_route]
Decorates a view function to register it for a PUT request at the specified URL rule. This is a convenient shortcut for route() with methods=["PUT"].
Parameters
| Name | Type | Description |
|---|
| rule | str | The URL rule string for the route. |
| options | t.Any | Extra options passed to the Werkzeug Rule object. |
Returns
| Type | Description |
|---|
t.Callable[[T_route], T_route] | A decorator that registers the view function for PUT requests. |
delete()
@classmethod
def delete(
rule: str,
options: t.Any
) - > t.Callable[[T_route], T_route]
Decorates a view function to register it for a DELETE request at the specified URL rule. This is a convenient shortcut for route() with methods=["DELETE"].
Parameters
| Name | Type | Description |
|---|
| rule | str | The URL rule string for the route. |
| options | t.Any | Extra options passed to the Werkzeug Rule object. |
Returns
| Type | Description |
|---|
t.Callable[[T_route], T_route] | A decorator that registers the view function for DELETE requests. |
patch()
@classmethod
def patch(
rule: str,
options: t.Any
) - > t.Callable[[T_route], T_route]
Decorates a view function to register it for a PATCH request at the specified URL rule. This is a convenient shortcut for route() with methods=["PATCH"].
Parameters
| Name | Type | Description |
|---|
| rule | str | The URL rule string for the route. |
| options | t.Any | Extra options passed to the Werkzeug Rule object. |
Returns
| Type | Description |
|---|
t.Callable[[T_route], T_route] | A decorator that registers the view function for PATCH requests. |
route()
@classmethod
def route(
rule: str,
options: t.Any
) - > t.Callable[[T_route], T_route]
Decorates 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.
Parameters
| Name | Type | Description |
|---|
| rule | str | The URL rule string. |
| options | t.Any | Extra options passed to the :class:~werkzeug.routing.Rule object. |
Returns
| Type | Description |
|---|
t.Callable[[T_route], T_route] | A decorator that registers the view function. |
add_url_rule()
@classmethod
def add_url_rule(
rule: str,
endpoint: str | None = None,
view_func: ft.RouteCallable | None = None,
provide_automatic_options: bool | None = None,
options: t.Any
) - > None
Registers a rule for routing incoming requests and building URLs. The :meth: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` = None |
| view_func | `ft.RouteCallable | None` = None |
| provide_automatic_options | `bool | None` = None |
| options | t.Any | Extra options passed to the :class:~werkzeug.routing.Rule object. |
Returns
| Type | Description |
|---|
None | This method does not return a value. |
endpoint()
@classmethod
def endpoint(
endpoint: str
) - > t.Callable[[F], F]
Decorates a view function to register it for the given endpoint. This is used when a rule is added without a view_func via add_url_rule() and the view function needs to be associated later.
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 view function with the specified endpoint. |
before_request()
@classmethod
def before_request(
f: T_before_request
) - > T_before_request
Registers a function to run before each request. This is useful for tasks like opening database connections or loading user data.
Parameters
| Name | Type | Description |
|---|
| f | T_before_request | The function to be registered, which will be called without arguments. |
Returns
| Type | Description |
|---|
T_before_request | The decorated function, allowing it to be chained or further decorated. |
after_request()
@classmethod
def after_request(
f: T_after_request
) - > T_after_request
Registers a function to run after each request to this object. The function receives the response object and must return a modified or new response object.
Parameters
| Name | Type | Description |
|---|
| f | T_after_request | The function to be registered, which will receive the response object as its argument. |
Returns
| Type | Description |
|---|
T_after_request | The decorated function, allowing it to be chained or further decorated. |
teardown_request()
@classmethod
def teardown_request(
f: T_teardown
) - > T_teardown
Registers a function to be called when the request context is popped, typically at the end of each request. This is suitable for cleanup tasks like closing resources, even if an exception occurred.
Parameters
| Name | Type | Description |
|---|
| f | T_teardown | The function to be registered, which may receive an error object if an unhandled exception occurred. |
Returns
| Type | Description |
|---|
T_teardown | The decorated function, allowing it to be chained or further decorated. |
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, and their returned dictionary keys are added as variables available in the template.
Parameters
| Name | Type | Description |
|---|
| f | T_template_context_processor | The function to be registered, which should return a dictionary of context variables. |
Returns
| Type | Description |
|---|
T_template_context_processor | The decorated function, allowing it to be chained or further decorated. |
url_value_preprocessor()
@classmethod
def url_value_preprocessor(
f: T_url_value_preprocessor
) - > T_url_value_preprocessor
Registers a URL value preprocessor function for all view functions. These functions are called before before_request functions and can modify values captured from the URL before they are passed to the view.
Parameters
| Name | Type | Description |
|---|
| f | T_url_value_preprocessor | The function to be registered, which receives the endpoint name and a dictionary of URL values. |
Returns
| Type | Description |
|---|
T_url_value_preprocessor | The decorated function, allowing it to be chained or further decorated. |
url_defaults()
@classmethod
def url_defaults(
f: T_url_defaults
) - > T_url_defaults
Registers a callback function for URL defaults for all view functions. This function is called with the endpoint and current values, and should update the values in place.
Parameters
| Name | Type | Description |
|---|
| f | T_url_defaults | The function to be registered, which receives the endpoint and a dictionary of URL values to modify. |
Returns
| Type | Description |
|---|
T_url_defaults | The decorated function, allowing it to be chained or further decorated. |
errorhandler()
@classmethod
def errorhandler(
code_or_exception: type[Exception]| int
) - > t.Callable[[T_error_handler], T_error_handler]
Registers a function to handle errors by a specific HTTP status code or exception class. This decorator allows custom error pages or handling logic for various error scenarios.
Parameters
| Name | Type | Description |
|---|
| code_or_exception | `type[Exception] | int` |
Returns
| Type | Description |
|---|
t.Callable[[T_error_handler], T_error_handler] | A decorator that registers the error handler function. |
register_error_handler()
@classmethod
def register_error_handler(
code_or_exception: type[Exception]| int,
f: ft.ErrorHandlerCallable
) - > None
Registers an error handler function for a given HTTP status code or exception class. This method provides an alternative to the errorhandler decorator for programmatic registration.
Parameters
| Name | Type | Description |
|---|
| code_or_exception | `type[Exception] | int` |
| f | ft.ErrorHandlerCallable | The error handler function to register. |
Returns
| Type | Description |
|---|
None | This method does not return a value. |