forked from orbit-oss/flask
Bugfix allow blueprints to be registered with a different name
This allows the same blueprint to be registered multiple times at the same level, but with differing url_prefixes and names.
This commit is contained in:
parent
141fde1d8e
commit
c2920e2bd9
2 changed files with 15 additions and 1 deletions
|
|
@ -274,7 +274,8 @@ class Blueprint(Scaffold):
|
|||
first_registration = False
|
||||
|
||||
name_prefix = options.get("name_prefix", "")
|
||||
name = f"{name_prefix}.{self.name}".lstrip(".")
|
||||
self_name = options.get("name", self.name)
|
||||
name = f"{name_prefix}.{self_name}".lstrip(".")
|
||||
|
||||
if name in app.blueprints and app.blueprints[name] is not self:
|
||||
raise ValueError(
|
||||
|
|
|
|||
|
|
@ -866,3 +866,16 @@ def test_nesting_url_prefixes(
|
|||
|
||||
response = client.get("/parent/child/")
|
||||
assert response.status_code == 200
|
||||
|
||||
|
||||
def test_unique_blueprint_names(app, client) -> None:
|
||||
bp = flask.Blueprint("bp", __name__)
|
||||
bp2 = flask.Blueprint("bp", __name__)
|
||||
|
||||
app.register_blueprint(bp)
|
||||
app.register_blueprint(bp) # same name, same object, no error
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
app.register_blueprint(bp2) # same name, different object
|
||||
|
||||
app.register_blueprint(bp2, name="alt") # different name
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue