-
-
Notifications
You must be signed in to change notification settings - Fork 16.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
blueprints are registered with nested names, can change registered name #4074
Conversation
I've added a I also think we should start issuing a deprecation warning if the same blueprint was registered with the same name, and eventually show the error for any name collisions, not just for different blueprints with the same name. |
a74ad01
to
3c4b40b
Compare
from flask import Blueprint
from flask import Flask
from flask import url_for
app = Flask(__name__)
bp = Blueprint("user", __name__)
@bp.get("/")
def index():
return url_for(".index")
app.register_blueprint(bp, url_prefix="/a")
app.register_blueprint(bp, name="user_b", url_prefix="/b") Navigating to both Looking at Map([<Rule '/a/' (GET, HEAD, OPTIONS) -> user.index>,
<Rule '/b/' (GET, HEAD, OPTIONS) -> user.index>,
<Rule '/static/<filename>' (GET, HEAD, OPTIONS) -> static>])
|
f5dbcf5
to
8b22fd4
Compare
This ensures that the url_prefix is correctly applied, no matter if set during the registration override or when constructing the blueprint.
Following discussions for Flask we've decided to name blueprints based on how they are registered. This allows for two different blueprints to have the same self-name as long as they are registered in different nested positions. This helps users choose better blueprint names.
This allows the same blueprint to be registered multiple times at the same level, but with differing url_prefixes and names.
By raising a ValueError if attempted. I don't see a use case that makes this worth supporting.
This ensures that if a blueprint is renamed at the time of registration that name is used when constructing endpoints, as expected.
name
can be passed as an option toregister_blueprint
. It changes the name the blueprint is registered with (or nested with). This allowsurl_for
to work if the same blueprint is registered with different prefixes. Fixes url_for can't distinguish a blueprint mounted two times #1091