Skip to content

Registering Blueprints

A blueprint only becomes active after you register it.

diagram a blueprint is a set of routes waiting for an application mermaid
Defining a blueprint registers nothing. The routes exist on the blueprint object, and only when the app registers it do they get a URL prefix and a namespaced endpoint. That is what lets the same blueprint be mounted at a different prefix, or in a different app, without editing it.
python
from flask import Flask
from auth.routes import auth_bp
 
app = Flask(__name__)
app.register_blueprint(auth_bp)

url_prefix groups routes under a prefix.

python
app.register_blueprint(auth_bp, url_prefix="/auth")

If a blueprint defines /login, it becomes:

  • /auth/login

Endpoints become namespaced by blueprint name:

  • auth.login

So in templates you’ll often do:

python
url_for("auth.login")

This avoids collisions when multiple blueprints have the same function name.

Blueprints can have their own templates folder, but many projects keep templates in one place.

Both approaches work; pick a convention and stay consistent.

pch.coffeeTagline

pch.coffeeCta

pch.feedbackHeading

pch.feedbackSubheading