Registering Blueprints
A blueprint only becomes active after you register it.
flowchart TD
A["bp = Blueprint('admin', __name__, url_prefix='/admin')"] --> B["@bp.route('/users')"]
B --> C["nothing is reachable yet -- there is no app"]
C --> D["app.register_blueprint(bp)"]
D --> E["rule becomes /admin/users"]
D --> F["endpoint becomes 'admin.users'"]
E --> G["url_for('admin.users') -> /admin/users"]
F --> G
H["app.route('/users') separately"] --> I["url_for('users') -> /users"]
G -.->|"no collision -- different endpoint names"| I
Basic registration
Section titled “Basic registration”from flask import Flask
from auth.routes import auth_bp
app = Flask(__name__)
app.register_blueprint(auth_bp)url_prefix
Section titled “url_prefix”url_prefix groups routes under a prefix.
app.register_blueprint(auth_bp, url_prefix="/auth")If a blueprint defines /login, it becomes:
/auth/login
Endpoint naming
Section titled “Endpoint naming”Endpoints become namespaced by blueprint name:
auth.login
So in templates you’ll often do:
url_for("auth.login")This avoids collisions when multiple blueprints have the same function name.
Where do templates live?
Section titled “Where do templates live?”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.coffeeCtapch.feedbackHeading
pch.feedbackSubheading