Flask Blueprints
A Blueprint is a self-contained collection of routes, templates, and static files that you define separately and then register on your Flask application, letting you split a growing project into clean, reusable modules.
Learn Flask Blueprints in our free Flask course — a beginner-friendly interactive lesson with worked examples, a practice exercise and a quick reference.
Part of the free Flask course at LearnCodingFast — hands-on lessons with examples you run in your browser, plus practice exercises and a quick quiz.
In this lesson you'll create your first Blueprint, register it on the app, give it a URL prefix, and learn how Blueprints keep large Flask projects organized.
A Blueprint is a reusable group of routes that you define independently from the application, then attach to it later. Think of it as a mini-application for one feature.
When every route lives in a single app.py , the file grows until it is impossible to navigate. Blueprints let you split your project by feature — one module for authentication, one for the blog, one for the admin panel — and register each on the main app.
You create a Blueprint with Blueprint(name, __name__) , define routes on it using @bp.route instead of @app.route , and finally call app.register_blueprint(bp) on your application.
The code below builds a small blog Blueprint and wires it into the app:
Notice the endpoint names print as blog.index and blog.show_post — the Blueprint name becomes a prefix on the endpoint, which is how you reference them in url_for . Run the real app with flask run to serve these pages.
Pass url_prefix when registering a Blueprint to mount all of its routes under one path. A route defined at / on a Blueprint registered with url_prefix="/blog" is served at /blog/ .
Prefixes keep features isolated: the blog lives under /blog , an admin Blueprint under /admin , and so on — with no route collisions.
Complete the code below. Replace each ___ so it creates an auth Blueprint, defines a login route, and registers it under /auth .
You probably forgot to call app.register_blueprint(bp) . Defining routes on a Blueprint does nothing until the Blueprint is registered on the app.
Blueprint endpoints are namespaced. Use the Blueprint name as a prefix in url_for , like url_for("blog.index") , not just "index" .
Build an app with two Blueprints so each feature has its own namespace.
Lesson 10 complete — your projects can now scale!
You can create a Blueprint, define routes on it, register it on the app, and group routes under a URL prefix. This is the foundation of every well-structured Flask project.
🚀 Up next: Database with SQLAlchemy — connect your app to a database and store real data.
Practice quiz
What is a Flask Blueprint?
- A reusable group of routes you register on an app
- A database migration tool
- A template inheritance system
- A type of config class
Answer: A reusable group of routes you register on an app. A Blueprint groups related routes, templates, and static files into a reusable component.
How do you create a Blueprint?
- Flask('blog')
- Blueprint('blog', __name__)
- app.blueprint('blog')
- register('blog')
Answer: Blueprint('blog', __name__). Create one with Blueprint(name, __name__).
Which decorator defines a route on a Blueprint named bp?
- @app.route
- @route.bp
- @bp.route
- @bp.view
Answer: @bp.route. Define routes on the Blueprint with @bp.route instead of @app.route.
How do you attach a Blueprint to the application?
- bp.attach(app)
- app.add_blueprint(bp)
- bp.register(app)
- app.register_blueprint(bp)
Answer: app.register_blueprint(bp). Call app.register_blueprint(bp) to attach it.
How do you mount every Blueprint route under /blog?
- register_blueprint(bp, url_prefix='/blog')
- Blueprint('blog', prefix='/blog')
- bp.route('/blog')
- app.prefix('/blog')
Answer: register_blueprint(bp, url_prefix='/blog'). Pass url_prefix when registering: register_blueprint(bp, url_prefix='/blog').
With a blog Blueprint, what is the endpoint name of its index view?
- index
- blog/index
- blog.index
- app.blog.index
Answer: blog.index. The Blueprint name prefixes the endpoint, so it becomes blog.index.
If Blueprint routes return 404, what did you likely forget?
- To call app.register_blueprint(bp)
- To set DEBUG=True
- To import jsonify
- To add a SECRET_KEY
Answer: To call app.register_blueprint(bp). Routes do nothing until the Blueprint is registered on the app.
How do you build a URL for a Blueprint endpoint?
- url_for('index')
- url_for('blog.index')
- url_for(blog, index)
- url_for('/blog/index')
Answer: url_for('blog.index'). Use the namespaced endpoint, like url_for('blog.index').
Why do production Flask apps use Blueprints?
- They are required by Flask
- They speed up the database
- They split features into clean, reusable modules
- They replace SECRET_KEY
Answer: They split features into clean, reusable modules. Blueprints keep large projects organized by splitting features into modules.
What is the second argument to Blueprint('blog', __name__) for?
- The URL prefix
- The route methods
- The database name
- Helping Flask locate templates and static files
Answer: Helping Flask locate templates and static files. __name__ helps Flask locate the Blueprint's templates and static files.