python
config_error
ai_generated
true
断言错误:蓝图名称冲突,两个名为 'api' 的蓝图被注册。
AssertionError: A blueprint's name collision occurred between <Blueprint 'api'> and <Blueprint 'api'>. Either specify a unique name or register them under different prefixes.
ID: python/flask-blueprint-name-conflict
80%修复率
88%置信度
0证据数
2025-07-30首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 2.x | active | — | — | — |
| 3.x | active | — | — | — |
根因分析
两个同名 Blueprint 对象注册到同一个 app,或同一蓝图被注册两次。
English
Two Blueprint objects with the same name are registered on the same app, or a blueprint is registered twice.
解决方案
-
95% 成功率
Give unique names: `api_v1 = Blueprint('api_v1', __name__)` and `api_v2 = Blueprint('api_v2', __name__)`. -
90% 成功率
Register with a prefix: `app.register_blueprint(api, url_prefix='/v1')` and ensure names differ.
无效尝试
常见但无效的做法:
-
90% 失败
Name still collides; url_prefix does not change the blueprint name.
-
85% 失败
Second blueprint's routes are silently dropped.