Skip to content

Introduction to Blueprints

Blueprints let you organize routes into modules.

Instead of one giant app.pyapp.py, you can split features like:

  • auth
  • blog
  • admin
  • api

Each module can own:

  • routes
  • templates
  • static files

Mental model

  • Flask()Flask() app is the “main application”
  • Blueprint()Blueprint() is a reusable, modular set of routes

false


  flowchart TB
  App[Flask App] --> BP1[auth Blueprint]
  App --> BP2[blog Blueprint]
  App --> BP3[api Blueprint]

false

Why Blueprints matter

  • Keeps routes manageable
  • Encourages separation of concerns
  • Makes collaboration easier
  • Works well with the app factory pattern

A simple blueprint

auth/routes.pyauth/routes.py:

from flask import Blueprint
 
auth_bp = Blueprint("auth", __name__)
 
 
auth_bp.route("/login")(lambda: "login")
from flask import Blueprint
 
auth_bp = Blueprint("auth", __name__)
 
 
auth_bp.route("/login")(lambda: "login")

You still must register the blueprint with the app (next page).

If this helped you, consider buying me a coffee ☕

Buy me a coffee

Was this page helpful?

Let us know how we did