Blueprint (Flask)
A Flask Blueprint is a way to group related routes, templates, and static files into a reusable component. You register the Blueprint on the app, which keeps large projects organized into modules like auth, blog, and admin.
Flask
As an app grows, putting every route in one file becomes unmanageable. A Blueprint lets you define a set of routes in its own module (e.g. auth.py) and then attach the whole group to the app at once. It is like a mini-application that does not run on its own.
You create one with bp = Blueprint('auth', __name__), decorate views with @bp.route instead of @app.route, then call app.register_blueprint(bp) — often with a url_prefix='/auth' so every route inside gains that prefix automatically.
A key consequence is that url_for must include the blueprint name: url_for('auth.login'). Blueprints can also have their own templates folder, error handlers, and before_request hooks scoped just to that blueprint.
Syntax
bp = Blueprint("name", __name__)
@bp.route("/")Examples
Python
from flask import Blueprint
auth = Blueprint("auth", __name__, url_prefix="/auth")
@auth.route("/login")
def login():
return "login page"
# in the app factory:
# app.register_blueprint(auth) -> route is /auth/login