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

其他格式: JSON · Markdown 中文 · English
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.

generic

解决方案

  1. 95% 成功率
    Give unique names: `api_v1 = Blueprint('api_v1', __name__)` and `api_v2 = Blueprint('api_v2', __name__)`.
  2. 90% 成功率
    Register with a prefix: `app.register_blueprint(api, url_prefix='/v1')` and ensure names differ.

无效尝试

常见但无效的做法:

  1. 90% 失败

    Name still collides; url_prefix does not change the blueprint name.

  2. 85% 失败

    Second blueprint's routes are silently dropped.