Skip to content

Registering Blueprints

A blueprint only becomes active after you register it.

Basic registration

from flask import Flask
from auth.routes import auth_bp
 
app = Flask(__name__)
app.register_blueprint(auth_bp)
from flask import Flask
from auth.routes import auth_bp
 
app = Flask(__name__)
app.register_blueprint(auth_bp)

url_prefix

url_prefixurl_prefix groups routes under a prefix.

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

If a blueprint defines /login/login, it becomes:

  • /auth/login/auth/login

Endpoint naming

Endpoints become namespaced by blueprint name:

  • auth.loginauth.login

So in templates you’ll often do:

url_for("auth.login")
url_for("auth.login")

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

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.

If this helped you, consider buying me a coffee ☕

Buy me a coffee

Was this page helpful?

Let us know how we did