← 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
Ready to go further?

These free tutorials are a preview, our Backend Development cohort covers it in depth, with a real project and a cohort alongside you. Closes Nov 30

Enroll in Backend Development

Cookie preferences

Choose what you're comfortable with. You can change this any time from the footer.

Don't miss out

Ready to build something real?

Create a free account to enroll in a track, and get notified the moment a cohort opens.

Create free account