Skip to main content

Scaffold

Common behavior shared between :class:~flask.Flask and :class:~flask.blueprints.Blueprint.

Attributes

AttributeTypeDescription
cliGroupThe Click command group for this object's CLI commands.
namestrThe 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

NameTypeDescription
import_namestrThe import name of the module where this object is defined. Usually name should be used.
static_folder`stros.PathLike[str]
static_url_path`strNone` = None
template_folder`stros.PathLike[str]
root_path`strNone` = 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

TypeDescription
`strNone`

has_static_folder()

@classmethod
def has_static_folder() - > bool

True if static_folder is set.

Returns

TypeDescription
boolA 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

TypeDescription
`strNone`

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

TypeDescription
`BaseLoaderNone`

get()

@classmethod
def get(
rule: str,
**options: t.Any
) - > t.Callable[[T_route], T_route]

Shortcut for route with methods=["GET"].

Parameters

NameTypeDescription
rulestrThe URL rule string.
**optionst.AnyExtra options passed to the Rule object.

Returns

TypeDescription
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

NameTypeDescription
rulestrThe URL rule string.
**optionst.AnyExtra options passed to the Rule object.

Returns

TypeDescription
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

NameTypeDescription
rulestrThe URL rule string.
**optionst.AnyExtra options passed to the Rule object.

Returns

TypeDescription
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

NameTypeDescription
rulestrThe URL rule string.
**optionst.AnyExtra options passed to the Rule object.

Returns

TypeDescription
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

NameTypeDescription
rulestrThe URL rule string.
**optionst.AnyExtra options passed to the Rule object.

Returns

TypeDescription
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

NameTypeDescription
rulestrThe URL rule string.
**optionst.AnyExtra options passed to the Rule object.

Returns

TypeDescription
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

NameTypeDescription
rulestrThe URL rule string.
endpoint`strNone`
view_func`ft.RouteCallableNone`
provide_automatic_options`boolNone`
**optionst.AnyExtra options passed to the Rule object.

Returns

TypeDescription
None

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

NameTypeDescription
endpointstrThe endpoint name to associate with the view function.

Returns

TypeDescription
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

NameTypeDescription
fT_before_requestThe function to call before handling the request.

Returns

TypeDescription
T_before_requestThe 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

NameTypeDescription
fT_after_requestThe function to call after handling the request, which must return a response.

Returns

TypeDescription
T_after_requestThe 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

NameTypeDescription
fT_teardownThe function to call during request context teardown.

Returns

TypeDescription
T_teardownThe 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

NameTypeDescription
fT_template_context_processorThe function that returns a dictionary of variables for the template context.

Returns

TypeDescription
T_template_context_processorThe 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

NameTypeDescription
fT_url_value_preprocessorThe function to process URL values before they reach the view.

Returns

TypeDescription
T_url_value_preprocessorThe 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

NameTypeDescription
fT_url_defaultsThe function to provide default values for URL generation.

Returns

TypeDescription
T_url_defaultsThe 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

NameTypeDescription
code_or_exception`type[Exception]int`

Returns

TypeDescription
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

NameTypeDescription
code_or_exception`type[Exception]int`
fft.ErrorHandlerCallableThe function to call when the error occurs.

Returns

TypeDescription
None