Blueprint

Flask introduces the concept of blueprint for developing application components and command patterns in an application or across multiple applications. It helps to comprehend large-scale applications by centralizing the root Flask application object. Blueprint acts as a separate Flask application without creating an actual Flask application object, and is able to instantiate application objects, initialize several extensions, and register a collection. It also provides template filters, static files, templates, and other utilities.

As explained in the auth module, we will also create the Blueprint instance for the Todo application. This will be configured in the app.__init__.py file, which is where we created the Flask application instance.

The following is a code snippet of the todo module's blueprint.

File—todo/__init__.py:

from flask import Blueprint

todo = Blueprint('todo', __name__)

from . import views

Once we have created the blueprint object of the todo module, we can use it to add routes in views and register the blueprint with the Flask application instance.

The following is the code snippet of app/__init__.py, which is where we are going to register blueprint:

from .auth import auth as auth_blueprint
from app.config import config

app = Flask(__name__)
app.config.from_object(config[environment])

app.register_blueprint(todo_blueprint, url_prefix='/todos')