Blueprint
This class provides a way to organize a group of related views and other code into a modular component that can be registered on an application. It supports defining static files, templates, and CLI commands that are scoped to the blueprint's namespace. By inheriting from a base implementation, it facilitates the creation of reusable application sub-sections with their own URL prefixes and subdomains.
Attributes
| Attribute | Type | Description |
|---|---|---|
| cli | [AppGroup](../cli/appgroup.md?sid=src_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
| Name | Type | Description |
|---|---|---|
| name | str | The name of the blueprint. Used for routing and endpoint names. |
| import_name | str | The name of the blueprint package, usually name. |
| static_folder | `str | os.PathLike[str] |
| static_url_path | `str | None` = None |
| template_folder | `str | os.PathLike[str] |
| 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 |
Signature
def Blueprint(
name: string,
import_name: string,
static_folder: string | os.PathLike[str]| null = null,
static_url_path: string | null = null,
template_folder: string | os.PathLike[str]| null = null,
url_prefix: string | null = null,
subdomain: string | null = null,
url_defaults: dict[str, t.Any]| null = null,
root_path: string | null = null,
cli_group: string | null = _sentinel
) - > null
Parameters
| Name | Type | Description |
|---|---|---|
| name | string | The name of the blueprint, used for routing and endpoint namespacing |
| import_name | string | The name of the package or module where the blueprint is defined |
| static_folder | `string | os.PathLike[str] |
| static_url_path | `string | null` = null |
| template_folder | `string | os.PathLike[str] |
| url_prefix | `string | null` = null |
| subdomain | `string | null` = null |
| url_defaults | `dict[str, t.Any] | null` = null |
| root_path | `string | null` = null |
| cli_group | `string | null` = _sentinel |
Methods
get_send_file_max_age()
@classmethod
def get_send_file_max_age(
filename: string | 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
| Name | Type | Description |
|---|---|---|
| filename | `string | null` |
Returns
| Type | Description |
|---|---|
| `int | null` |
send_static_file()
@classmethod
def send_static_file(
filename: string
) - > [Response](../wrappers/response.md?sid=src_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
| Name | Type | Description |
|---|---|---|
| filename | string | The path of the static file relative to the static folder |
Returns
| Type | Description |
|---|---|
[Response](../wrappers/response.md?sid=src_flask_wrappers_response) | A response object containing the requested static file |
open_resource()
@classmethod
def open_resource(
resource: string,
mode: string = "rb",
encoding: string | null = "utf-8"
) - > 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
| Name | Type | Description |
|---|---|---|
| resource | string | Path to the resource relative to :attr:root_path. |
| mode | string = "rb" | Open the file in this mode. Only reading is supported, valid values are "r" (or "rt") and "rb". |
| encoding | `string | null` = "utf-8" |
Returns
| Type | Description |
|---|---|
t.IO[t.AnyStr] | A file-like object for the requested resource |