MSK Institute LogoMSK.Institute
HomeCourses
Book Free Demo➔Sign In
Free Demo➔
MSK Institute LogoMSK.Institute

Leading computer training academy in Shikohabad for software engineering, Python, web development, and digital literacy.

ISO 9001:2015 Certified Center
Follow & Connect
4.9

Programs & Admissions

  • All CoursesCatalog
  • Learning PathsRoadmaps
  • Student ProjectsShowcase
  • Live Classes & ScheduleLive
  • Upcoming Batches
  • Campuses & LocationsHub
  • Verify Certificates
  • Book Free Demo Class

Resources & Tools

  • Free Online Mock TestsAll Tests
  • NIELIT CCC Mock TestFree
  • Course & Career FinderQuiz
  • Study Material Hub
  • All MSK ToolsHub
  • Keyboard ShortcutsNew
  • TypeQuest Speed LabTyping
  • MSK Code PlaygroundCode
  • Interactive Tutorials
  • Quick Cheatsheets

Institute & Contact

  • About MSK Institute
  • Careers & InternshipsHiring
  • Publications & Blogs
  • Gali No. 3, Near Gyan Jyoti Public School,
    Adarsh Nagar, Shikohabad, Uttar Pradesh 283135
  • +91 83930 42166
  • mskshikohabad@gmail.com
  • Hours:Mon – Sat: 8:00 AM – 7:00 PM | Sun: 10:00 AM – 2:00 PM
  • 4.9 ★(38 Google Reviews)
© 2026 MSK Institute. All rights reserved.•Privacy Policy•Terms of Service•Disclaimer•Contact Us

Shikohabad's Leading Computer & Coding Academy

Home
Courses
Live
Material
Modular Routing with Flask Blueprints0%
Study Materials
FlaskProgress 0%
1.1What is Flask & WSGI Architecture1.2Virtual Environments & First Flask Application1.3Flask CLI & Environment Configuration
7.1Modular Routing with Flask Blueprints7.2The Application Factory Pattern (create_app)
HomeTutorialsFlaskModular Routing with Flask Blueprints
The Application Factory Pattern (create_app)

Modular Routing with Flask Blueprints

Beginner12 min read•Updated: 2026-09-16•By Er. Sumit Kumar (MSK Institute)
Study MaterialsCheatsheet

Putting all routes, models, and helper functions in a single app.py file works for prototypes, but enterprise applications quickly become unmaintainable as they grow to dozens of endpoints.

Flask Blueprints provide a modular pattern for dividing an application into reusable, self-contained components—such as an authentication module, an administrative portal, and a public API.


1. What is a Blueprint?

A Blueprint is essentially a recording object for application components (routes, error handlers, static files, and templates). Instead of registering routes directly with app, you register them with the Blueprint. Later, the Blueprint is registered onto the core application instance.

Visual Architecture Blueprint
+-------------------------------------------------------------------------------+
|                            Flask Application (app)                            |
+-------------------------------------------------------------------------------+
        |                               |                               |
        v                               v                               v
+----------------+              +----------------+              +---------------+
| auth_bp        |              | courses_bp     |              | api_bp        |
| prefix: /auth  |              | prefix: /courses|             | prefix: /api  |
+----------------+              +----------------+              +---------------+
| /login         |              | /              |              | /v1/users     |
| /logout        |              | /<slug>        |              | /v1/checkout  |
| /register      |              | /enroll        |              | /v1/analytics |
+----------------+              +----------------+              +---------------+

2. Directory Structure for Blueprint-Driven Applications

1my_enterprise_app/
2├── app/
3│ ├── __init__.py # Initializes app and registers blueprints
4│ ├── auth/ # Auth Blueprint
5│ │ ├── __init__.py
6│ │ ├── routes.py
7│ │ └── forms.py
8│ ├── courses/ # Courses Blueprint
9│ │ ├── __init__.py
10│ │ └── routes.py
11│ ├── api/ # REST API Blueprint
12│ │ ├── __init__.py
13│ │ └── routes.py
14│ ├── templates/
15│ │ ├── auth/
16│ │ └── courses/
17│ └── static/
18├── config.py
19└── run.py

3. Defining a Blueprint

In app/auth/routes.py:

1from flask import Blueprint, render_template, redirect, url_for, flash
2 
3# Instantiate Blueprint
4# First argument: Blueprint name
5# Second argument: import_name (__name__)
6# Optional: template_folder and url_prefix
7auth_bp = Blueprint("auth", __name__, url_prefix="/auth", template_folder="templates")
8 
9@auth_bp.route("/login", methods=["GET", "POST"])
10def login():
11 return render_template("auth/login.html")
12 
13@auth_bp.route("/logout")
14def logout():
15 flash("Signed out successfully", "info")
16 return redirect(url_for("auth.login")) # Note blueprint namespace!

4. Registering Blueprints with the Application

In app/__init__.py:

1from flask import Flask
2from app.auth.routes import auth_bp
3from app.courses.routes import courses_bp
4from app.api.routes import api_bp
5 
6def create_app():
7 app = Flask(__name__)
8 app.config["SECRET_KEY"] = "dev-secret"
9 
10 # Register blueprints onto application
11 app.register_blueprint(auth_bp)
12 app.register_blueprint(courses_bp, url_prefix="/courses")
13 app.register_blueprint(api_bp, url_prefix="/api/v1")
14 
15 return app

5. Reverse Routing with Blueprint Namespaces

When using Blueprints, url_for() requires the blueprint name as a prefix separated by a dot:

1# Absolute blueprint endpoint
2url_for("auth.login") # Resolves to /auth/login
3url_for("courses.detail", slug="python") # Resolves to /courses/python
4 
5# Relative shorthand within the SAME blueprint
6url_for(".login") # Resolves to auth.login if invoked inside auth_bp!

Interactive Quiz• Knowledge Check

Practice Quiz

Question 1
What is the primary purpose of Flask Blueprints?
Question 2
How is a route inside a blueprint named admin resolved using url_for()?
Question 3
What does the url_prefix parameter do when registering a blueprint?
Question 4
Can a blueprint define its own dedicated static_folder and template_folder?
Question 5
How do you refer to a view function in the current blueprint using relative endpoint notation?
Next Lesson

The Application Factory Pattern (create_app)

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Related Lessons

Previous LessonNext Lesson
Role-Based Access Control & Custom DecoratorsThe Application Factory Pattern (create_app)

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

Mentor-Led Practical Training

Master Flask with Hands-On Projects

Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.

View Full CourseBook Free Demo
PreviousNext
PreviousPrevNext