class flask.Blueprint(name, import_name, static_folder=None, static_url_path=None, template_folder=None, url_prefix=None, subdomain=None, url_defaults=None, root_path=None, cli_group=<object object>)  
Represents a blueprint, a collection of routes and other app-related functions that can be registered on a real application later. A blueprint is an object that allows defining application functions without requiring an application object ahead of time. It uses the same decorators as Flask, but defers the need for an application by recording them for later registration. Decorating a function with a blueprint creates a deferred function that is called with BlueprintSetupState when the blueprint is registered on an application. See Modular Applications with Blueprints for more information.  Parameters 
 
name (str) – The name of the blueprint. Will be prepended to each endpoint name. 
import_name (str) – The name of the blueprint package, usually __name__. This helps locate the root_path for the blueprint. 
static_folder (Optional[str]) – A folder with static files that should be served by the blueprint’s static route. The path is relative to the blueprint’s root path. Blueprint static files are disabled by default. 
static_url_path (Optional[str]) – The url to serve static files from. Defaults to static_folder. If the blueprint does not have a url_prefix, the app’s static route will take precedence, and the blueprint’s static files won’t be accessible. 
template_folder (Optional[str]) – A folder with templates that should be added to the app’s template search path. The path is relative to the blueprint’s root path. Blueprint templates are disabled by default. Blueprint templates have a lower precedence than those in the app’s templates folder. 
url_prefix (Optional[str]) – A path to prepend to all of the blueprint’s URLs, to make them distinct from the rest of the app’s routes. 
subdomain (Optional[str]) – A subdomain that blueprint routes will match on by default. 
url_defaults (Optional[dict]) – A dict of default values that blueprint routes will receive by default. 
root_path (Optional[str]) – By default, the blueprint will automatically set this based on import_name. In certain situations this automatic detection can fail, so the path can be specified manually instead. 
cli_group (Optional[str]) –      Changelog Changed in version 1.1.0: Blueprints have a cli group to register nested CLI commands. The cli_group parameter controls the name of the group under the flask command.   New in version 0.7.   
add_app_template_filter(f, name=None)  
Register a custom template filter, available application wide. Like Flask.add_template_filter() but for a blueprint. Works exactly like the app_template_filter() decorator.  Parameters 
 
name (Optional[str]) – the optional name of the filter, otherwise the function name will be used. 
f (Callable[[Any], str]) –    Return type 
None   
  
add_app_template_global(f, name=None)  
Register a custom template global, available application wide. Like Flask.add_template_global() but for a blueprint. Works exactly like the app_template_global() decorator.  Changelog New in version 0.10.   Parameters 
 
name (Optional[str]) – the optional name of the global, otherwise the function name will be used. 
f (Callable[[], Any]) –    Return type 
None   
  
add_app_template_test(f, name=None)  
Register a custom template test, available application wide. Like Flask.add_template_test() but for a blueprint. Works exactly like the app_template_test() decorator.  Changelog New in version 0.10.   Parameters 
 
name (Optional[str]) – the optional name of the test, otherwise the function name will be used. 
f (Callable[[Any], bool]) –    Return type 
None   
  
add_url_rule(rule, endpoint=None, view_func=None, **options)  
Like Flask.add_url_rule() but for a blueprint. The endpoint for the url_for() function is prefixed with the name of the blueprint.  Parameters 
 
rule (str) –  
endpoint (Optional[str]) –  
view_func (Optional[Callable]) –  
options (Any) –    Return type 
None   
  
after_app_request(f)  
Like Flask.after_request() but for a blueprint. Such a function is executed after each request, even if outside of the blueprint.  Parameters 
f (Callable[[Response], Response]) –   Return type 
Callable[[Response], Response]   
  
after_request(f)  
Register a function to run after each request to this object. The function is called with the response object, and must return a response object. This allows the functions to modify or replace the response before it is sent. If a function raises an exception, any remaining after_request functions will not be called. Therefore, this should not be used for actions that must execute, such as to close resources. Use teardown_request() for that.  Parameters 
f (Callable[[Response], Response]) –   Return type 
Callable[[Response], Response]   
  
after_request_funcs: t.Dict[AppOrBlueprintKey, t.List[AfterRequestCallable]]  
A data structure of functions to call at the end of each request, in the format {scope: [functions]}. The scope key is the name of a blueprint the functions are active for, or None for all requests. To register a function, use the after_request() decorator. This data structure is internal. It should not be modified directly and its format may change at any time. 
  
app_context_processor(f)  
Like Flask.context_processor() but for a blueprint. Such a function is executed each request, even if outside of the blueprint.  Parameters 
f (Callable[[], Dict[str, Any]]) –   Return type 
Callable[[], Dict[str, Any]]   
  
app_errorhandler(code)  
Like Flask.errorhandler() but for a blueprint. This handler is used for all requests, even if outside of the blueprint.  Parameters 
code (Union[Type[Exception], int]) –   Return type 
Callable   
  
app_template_filter(name=None)  
Register a custom template filter, available application wide. Like Flask.template_filter() but for a blueprint.  Parameters 
name (Optional[str]) – the optional name of the filter, otherwise the function name will be used.  Return type 
Callable   
  
app_template_global(name=None)  
Register a custom template global, available application wide. Like Flask.template_global() but for a blueprint.  Changelog New in version 0.10.   Parameters 
name (Optional[str]) – the optional name of the global, otherwise the function name will be used.  Return type 
Callable   
  
app_template_test(name=None)  
Register a custom template test, available application wide. Like Flask.template_test() but for a blueprint.  Changelog New in version 0.10.   Parameters 
name (Optional[str]) – the optional name of the test, otherwise the function name will be used.  Return type 
Callable   
  
app_url_defaults(f)  
Same as url_defaults() but application wide.  Parameters 
f (Callable[[str, dict], None]) –   Return type 
Callable[[str, dict], None]   
  
app_url_value_preprocessor(f)  
Same as url_value_preprocessor() but application wide.  Parameters 
f (Callable[[Optional[str], Optional[dict]], None]) –   Return type 
Callable[[Optional[str], Optional[dict]], None]   
  
before_app_first_request(f)  
Like Flask.before_first_request(). Such a function is executed before the first request to the application.  Parameters 
f (Callable[[], None]) –   Return type 
Callable[[], None]   
  
before_app_request(f)  
Like Flask.before_request(). Such a function is executed before each request, even if outside of a blueprint.  Parameters 
f (Callable[[], None]) –   Return type 
Callable[[], None]   
  
before_request(f)  
Register a function to run before each request. For example, this can be used to open a database connection, or to load the logged in user from the session. @app.before_request
def load_user():
    if "user_id" in session:
        g.user = db.session.get(session["user_id"])
 The function will be called without any arguments. If it returns a non-None value, the value is handled as if it was the return value from the view, and further request handling is stopped.  Parameters 
f (Callable[[], None]) –   Return type 
Callable[[], None]   
  
before_request_funcs: t.Dict[AppOrBlueprintKey, t.List[BeforeRequestCallable]]  
A data structure of functions to call at the beginning of each request, in the format {scope: [functions]}. The scope key is the name of a blueprint the functions are active for, or None for all requests. To register a function, use the before_request() decorator. This data structure is internal. It should not be modified directly and its format may change at any time. 
  
cli  
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. 
  
context_processor(f)  
Registers a template context processor function.  Parameters 
f (Callable[[], Dict[str, Any]]) –   Return type 
Callable[[], Dict[str, Any]]   
  
delete(rule, **options)  
Shortcut for route() with methods=["DELETE"].  New in version 2.0.   Parameters 
 
rule (str) –  
options (Any) –    Return type 
Callable   
  
endpoint(endpoint)  
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(). app.add_url_rule("/ex", endpoint="example")

@app.endpoint("example")
def example():
    ...
  Parameters 
endpoint (str) – The endpoint name to associate with the view function.  Return type 
Callable   
  
error_handler_spec: t.Dict[AppOrBlueprintKey, t.Dict[t.Optional[int], t.Dict[t.Type[Exception], ErrorHandlerCallable]]]  
A data structure of registered error handlers, in the format {scope: {code: {class: handler}}}`. The scope key is the name of a blueprint the handlers are active for, or None for all requests. The code key is the HTTP status code for HTTPException, or None for other exceptions. The innermost dictionary maps exception classes to handler functions. To register an error handler, use the errorhandler() decorator. This data structure is internal. It should not be modified directly and its format may change at any time. 
  
errorhandler(code_or_exception)  
Register a function to handle errors by code or exception class. A decorator that is used to register a function given an error code. Example: @app.errorhandler(404)
def page_not_found(error):
    return 'This page does not exist', 404
 You can also register handlers for arbitrary exceptions: @app.errorhandler(DatabaseError)
def special_exception_handler(error):
    return 'Database connection failed', 500
  Changelog New in version 0.7: Use register_error_handler() instead of modifying error_handler_spec directly, for application wide error handlers.   New in version 0.7: One can now additionally also register custom exception types that do not necessarily have to be a subclass of the HTTPException class.   Parameters 
code_or_exception (Union[Type[Exception], int]) – the code as integer for the handler, or an arbitrary exception  Return type 
Callable   
  
get(rule, **options)  
Shortcut for route() with methods=["GET"].  New in version 2.0.   Parameters 
 
rule (str) –  
options (Any) –    Return type 
Callable   
  
get_send_file_max_age(filename)  
Used by send_file() to determine the max_age cache value for a given file path if it wasn’t passed. By default, this returns SEND_FILE_MAX_AGE_DEFAULT from the configuration of current_app. This defaults to None, which tells the browser to use conditional requests instead of a timed cache, which is usually preferable.  Changed in version 2.0: The default configuration is None instead of 12 hours.   Changelog New in version 0.9.   Parameters 
filename (str) –   Return type 
Optional[int]   
  
property has_static_folder: bool  
True if static_folder is set.  Changelog New in version 0.5.  

  
import_name  
The name of the package or module that this object belongs to. Do not change this once it is set by the constructor. 
  
property jinja_loader: Optional[jinja2.loaders.FileSystemLoader]  
The Jinja loader for this object’s templates. By default this is a class jinja2.loaders.FileSystemLoader to template_folder if it is set.  Changelog New in version 0.5.  

  
json_decoder: Optional[Type[json.decoder.JSONDecoder]] = None  
Blueprint local JSON decoder class to use. Set to None to use the app’s json_decoder. 
  
json_encoder: Optional[Type[json.encoder.JSONEncoder]] = None  
Blueprint local JSON encoder class to use. Set to None to use the app’s json_encoder. 
  
make_setup_state(app, options, first_registration=False)  
Creates an instance of BlueprintSetupState() object that is later passed to the register callback functions. Subclasses can override this to return a subclass of the setup state.  Parameters 
 
app (Flask) –  
options (dict) –  
first_registration (bool) –    Return type 
flask.blueprints.BlueprintSetupState   
  
open_resource(resource, mode='rb')  
Open a resource file relative to root_path for reading. For example, if the file schema.sql is next to the file app.py where the Flask app is defined, it can be opened with: with app.open_resource("schema.sql") as f:
    conn.executescript(f.read())
  Parameters 
 
resource (str) – Path to the resource relative to root_path. 
mode (str) – Open the file in this mode. Only reading is supported, valid values are “r” (or “rt”) and “rb”.   Return type 
IO   
  
patch(rule, **options)  
Shortcut for route() with methods=["PATCH"].  New in version 2.0.   Parameters 
 
rule (str) –  
options (Any) –    Return type 
Callable   
  
post(rule, **options)  
Shortcut for route() with methods=["POST"].  New in version 2.0.   Parameters 
 
rule (str) –  
options (Any) –    Return type 
Callable   
  
put(rule, **options)  
Shortcut for route() with methods=["PUT"].  New in version 2.0.   Parameters 
 
rule (str) –  
options (Any) –    Return type 
Callable   
  
record(func)  
Registers a function that is called when the blueprint is registered on the application. This function is called with the state as argument as returned by the make_setup_state() method.  Parameters 
func (Callable) –   Return type 
None   
  
record_once(func)  
Works like record() but wraps the function in another function that will ensure the function is only called once. If the blueprint is registered a second time on the application, the function passed is not called.  Parameters 
func (Callable) –   Return type 
None   
  
register(app, options)  
Called by Flask.register_blueprint() to register all views and callbacks registered on the blueprint with the application. Creates a BlueprintSetupState and calls each record() callbackwith it.  Parameters 
 
app (Flask) – The application this blueprint is being registered with. 
options (dict) – Keyword arguments forwarded from register_blueprint(). 
first_registration – Whether this is the first time this blueprint has been registered on the application.   Return type 
None   
  
register_blueprint(blueprint, **options)  
Register a Blueprint on this blueprint. Keyword arguments passed to this method will override the defaults set on the blueprint.  New in version 2.0.   Parameters 
 
blueprint (flask.blueprints.Blueprint) –  
options (Any) –    Return type 
None   
  
register_error_handler(code_or_exception, f)  
Alternative error attach function to the errorhandler() decorator that is more straightforward to use for non decorator usage.  Changelog New in version 0.7.   Parameters 
 
code_or_exception (Union[Type[Exception], int]) –  
f (Callable[[Exception], Union[Response, AnyStr, Dict[str, Any], Generator[AnyStr, None, None], Tuple[Union[Response, AnyStr, Dict[str, Any], Generator[AnyStr, None, None]], Union[Headers, Dict[str, Union[str, List[str], Tuple[str, ...]]], List[Tuple[str, Union[str, List[str], Tuple[str, ...]]]]]], Tuple[Union[Response, AnyStr, Dict[str, Any], Generator[AnyStr, None, None]], int], Tuple[Union[Response, AnyStr, Dict[str, Any], Generator[AnyStr, None, None]], int, Union[Headers, Dict[str, Union[str, List[str], Tuple[str, ...]]], List[Tuple[str, Union[str, List[str], Tuple[str, ...]]]]]], WSGIApplication]]) –    Return type 
None   
  
root_path  
Absolute path to the package on the filesystem. Used to look up resources contained in the package. 
  
route(rule, **options)  
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. @app.route("/")
def index():
    return "Hello, World!"
 See URL Route Registrations. The endpoint name for the route defaults to the name of the view function if the endpoint parameter isn’t passed. The methods parameter defaults to ["GET"]. HEAD and OPTIONS are added automatically.  Parameters 
 
rule (str) – The URL rule string. 
options (Any) – Extra options passed to the Rule object.   Return type 
Callable   
  
send_static_file(filename)  
The view function used to serve files from static_folder. A route is automatically registered for this view at static_url_path if static_folder is set.  Changelog New in version 0.5.   Parameters 
filename (str) –   Return type 
Response   
  
property static_folder: Optional[str]  
The absolute path to the configured static folder. None if no static folder is set. 
  
property static_url_path: Optional[str]  
The URL prefix that the static route will be accessible from. If it was not configured during init, it is derived from static_folder. 
  
teardown_app_request(f)  
Like Flask.teardown_request() but for a blueprint. Such a function is executed when tearing down each request, even if outside of the blueprint.  Parameters 
f (Callable[[Optional[BaseException]], Response]) –   Return type 
Callable[[Optional[BaseException]], Response]   
  
teardown_request(f)  
Register a function to be run at the end of each request, regardless of whether there was an exception or not. These functions are executed when the request context is popped, even if not an actual request was performed. Example: ctx = app.test_request_context()
ctx.push()
...
ctx.pop()
 When ctx.pop() is executed in the above example, the teardown functions are called just before the request context moves from the stack of active contexts. This becomes relevant if you are using such constructs in tests. Teardown functions must avoid raising exceptions, since they . If they execute code that might fail they will have to surround the execution of these code by try/except statements and log occurring errors. When a teardown function was called because of an exception it will be passed an error object. The return values of teardown functions are ignored.  Debug Note In debug mode Flask will not tear down a request on an exception immediately. Instead it will keep it alive so that the interactive debugger can still access it. This behavior can be controlled by the PRESERVE_CONTEXT_ON_EXCEPTION configuration variable.   Parameters 
f (Callable[[Optional[BaseException]], Response]) –   Return type 
Callable[[Optional[BaseException]], Response]   
  
teardown_request_funcs: t.Dict[AppOrBlueprintKey, t.List[TeardownCallable]]  
A data structure of functions to call at the end of each request even if an exception is raised, in the format {scope: [functions]}. The scope key is the name of a blueprint the functions are active for, or None for all requests. To register a function, use the teardown_request() decorator. This data structure is internal. It should not be modified directly and its format may change at any time. 
  
template_context_processors: t.Dict[AppOrBlueprintKey, t.List[TemplateContextProcessorCallable]]  
A data structure of functions to call to pass extra context values when rendering templates, in the format {scope: [functions]}. The scope key is the name of a blueprint the functions are active for, or None for all requests. To register a function, use the context_processor() decorator. This data structure is internal. It should not be modified directly and its format may change at any time. 
  
template_folder  
The path to the templates folder, relative to root_path, to add to the template loader. None if templates should not be added. 
  
url_default_functions: t.Dict[AppOrBlueprintKey, t.List[URLDefaultCallable]]  
A data structure of functions to call to modify the keyword arguments when generating URLs, in the format {scope: [functions]}. The scope key is the name of a blueprint the functions are active for, or None for all requests. To register a function, use the url_defaults() decorator. This data structure is internal. It should not be modified directly and its format may change at any time. 
  
url_defaults(f)  
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 
f (Callable[[str, dict], None]) –   Return type 
Callable[[str, dict], None]   
  
url_value_preprocessor(f)  
Register a URL value preprocessor function for all view functions in the application. These functions will be called before the before_request() functions. The function can modify the values captured from the matched url before they are passed to the view. For example, this can be used to pop a common language code value and place it in g rather than pass it to every view. The function is passed the endpoint name and values dict. The return value is ignored.  Parameters 
f (Callable[[Optional[str], Optional[dict]], None]) –   Return type 
Callable[[Optional[str], Optional[dict]], None]   
  
url_value_preprocessors: t.Dict[AppOrBlueprintKey, t.List[URLValuePreprocessorCallable]]  
A data structure of functions to call to modify the keyword arguments passed to the view function, in the format {scope: [functions]}. The scope key is the name of a blueprint the functions are active for, or None for all requests. To register a function, use the url_value_preprocessor() decorator. This data structure is internal. It should not be modified directly and its format may change at any time. 
  
view_functions: t.Dict[str, t.Callable]  
A dictionary mapping endpoint names to view functions. To register a view function, use the route() decorator. This data structure is internal. It should not be modified directly and its format may change at any time.