Skip to main content

Blueprint

This class provides a mechanism for organizing an application into distinct components by grouping related views, templates, and static files. It supports the registration of CLI commands through a dedicated command group and includes utilities for opening blueprint-relative resources and serving static files. By inheriting from a base implementation, it allows for modular application design with configurable URL prefixes and subdomains.

Attributes

AttributeTypeDescription
cli[AppGroup](../cli/appgroup.md?sid=flask_cli_appgroup) = AppGroup()The Click command group for registering CLI commands for this object. The commands are available from the flask command once the application has been discovered and blueprints have been registered.

Constructor

Signature

def Blueprint(
name: str,
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,
url_prefix: str | None = None,
subdomain: str | None = None,
url_defaults: dict[str, t.Any]| None = None,
root_path: str | None = None,
cli_group: str | None = _sentinel
) - > None

Parameters

NameTypeDescription
namestrThe name of the blueprint. Used for routing and endpoint names.
import_namestrThe name of the blueprint package, usually name.
static_folder`stros.PathLike[str]
static_url_path`strNone` = None
template_folder`stros.PathLike[str]
url_prefix`strNone` = None
subdomain`strNone` = None
url_defaults`dict[str, t.Any]None` = None
root_path`strNone` = None
cli_group`strNone` = _sentinel

Signature

def Blueprint(
name: str,
import_name: str,
static_folder: str | os.PathLike[str]| null = null,
static_url_path: str | null = null,
template_folder: str | os.PathLike[str]| null = null,
url_prefix: str | null = null,
subdomain: str | null = null,
url_defaults: dict[str, t.Any]| null = null,
root_path: str | null = null,
cli_group: str | null = _sentinel
) - > null

Parameters

NameTypeDescription
namestrThe name of the blueprint used for endpoint prefixing and internal identification
import_namestrThe name of the module where the blueprint is defined, used to locate resources
static_folder`stros.PathLike[str]
static_url_path`strnull` = null
template_folder`stros.PathLike[str]
url_prefix`strnull` = null
subdomain`strnull` = null
url_defaults`dict[str, t.Any]null` = null
root_path`strnull` = null
cli_group`strnull` = _sentinel

Methods


get_send_file_max_age()

@classmethod
def get_send_file_max_age(
filename: str | null
) - > int | null

Used by :func:send_file to determine the max_age cache value for a given file path if it wasn't passed.

Parameters

NameTypeDescription
filename`strnull`

Returns

TypeDescription
`intnull`

send_static_file()

@classmethod
def send_static_file(
filename: str
) - > [Response](../wrappers/response.md?sid=flask_wrappers_response)

The view function used to serve files from :attr:static_folder. A route is automatically registered for this view at :attr:static_url_path if :attr:static_folder is set.

Parameters

NameTypeDescription
filenamestrThe relative path to the file within the blueprint's static folder

Returns

TypeDescription
[Response](../wrappers/response.md?sid=flask_wrappers_response)A response object containing the requested static file's content

open_resource()

@classmethod
def open_resource(
resource: str,
mode: str,
encoding: str | null
) - > t.IO[t.AnyStr]

Open a resource file relative to :attr:root_path for reading. The blueprint-relative equivalent of the app's :meth:~.Flask.open_resource method.

Parameters

NameTypeDescription
resourcestrPath to the resource relative to :attr:root_path.
modestrOpen the file in this mode. Only reading is supported, valid values are "r" (or "rt") and "rb".
encoding`strnull`

Returns

TypeDescription
t.IO[t.AnyStr]A file-like object opened for reading the specified resource