Skip to main content

Scaffold

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

Attributes

AttributeTypeDescription
cliGroupThis attribute stores a Group object, which is used for command-line interface functionalities.
namestrThis 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

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

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

TypeDescription
`strNone`

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

NameTypeDescription
value`stros.PathLike[str]

Returns

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

TypeDescription
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

TypeDescription
`strNone`

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

NameTypeDescription
value`strNone`

Returns

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

TypeDescription
`BaseLoaderNone`

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

NameTypeDescription
rulestrThe URL rule string for the route.
optionst.AnyExtra options passed to the Werkzeug Rule object.

Returns

TypeDescription
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

NameTypeDescription
rulestrThe URL rule string for the route.
optionst.AnyExtra options passed to the Werkzeug Rule object.

Returns

TypeDescription
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

NameTypeDescription
rulestrThe URL rule string for the route.
optionst.AnyExtra options passed to the Werkzeug Rule object.

Returns

TypeDescription
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

NameTypeDescription
rulestrThe URL rule string for the route.
optionst.AnyExtra options passed to the Werkzeug Rule object.

Returns

TypeDescription
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

NameTypeDescription
rulestrThe URL rule string for the route.
optionst.AnyExtra options passed to the Werkzeug Rule object.

Returns

TypeDescription
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

NameTypeDescription
rulestrThe URL rule string.
optionst.AnyExtra options passed to the :class:~werkzeug.routing.Rule object.

Returns

TypeDescription
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

NameTypeDescription
rulestrThe URL rule string.
endpoint`strNone` = None
view_func`ft.RouteCallableNone` = None
provide_automatic_options`boolNone` = None
optionst.AnyExtra options passed to the :class:~werkzeug.routing.Rule object.

Returns

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

NameTypeDescription
endpointstrThe endpoint name to associate with the view function.

Returns

TypeDescription
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

NameTypeDescription
fT_before_requestThe function to be registered, which will be called without arguments.

Returns

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

NameTypeDescription
fT_after_requestThe function to be registered, which will receive the response object as its argument.

Returns

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

NameTypeDescription
fT_teardownThe function to be registered, which may receive an error object if an unhandled exception occurred.

Returns

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

NameTypeDescription
fT_template_context_processorThe function to be registered, which should return a dictionary of context variables.

Returns

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

NameTypeDescription
fT_url_value_preprocessorThe function to be registered, which receives the endpoint name and a dictionary of URL values.

Returns

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

NameTypeDescription
fT_url_defaultsThe function to be registered, which receives the endpoint and a dictionary of URL values to modify.

Returns

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

NameTypeDescription
code_or_exception`type[Exception]int`

Returns

TypeDescription
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

NameTypeDescription
code_or_exception`type[Exception]int`
fft.ErrorHandlerCallableThe error handler function to register.

Returns

TypeDescription
NoneThis method does not return a value.