← Flask tutorial

Flask

Blueprints

As a Flask app grows past a handful of routes, a Blueprint lets you group related routes into their own file or module, then register it on the main app.

Example: a blueprint for a blog section

# blog/routes.py
from flask import Blueprint

blog = Blueprint("blog", __name__)

@blog.route("/blog")
def blog_home():
    return "Welcome to the blog"

# app.py
from blog.routes import blog
app.register_blueprint(blog)
Visiting /blog now returns: Welcome to the blog

This is Flask's version of splitting a project into pieces, similar in spirit to how a Django project splits into multiple apps (like this platform's own tutorials and courses apps) — each blueprint owns its own routes, keeping one giant app.py from becoming unmanageable as a real project grows.

Example
# blog/routes.py
from flask import Blueprint

blog = Blueprint("blog", __name__)

@blog.route("/blog")
def blog_home():
    return "Welcome to the blog"

# app.py
from blog.routes import blog
app.register_blueprint(blog)
Output
Visiting /blog now returns: Welcome to the blog