python config_error ai_generated true

AssertionError: View function mapping is overwriting an existing endpoint function: main.index

ID: python/flask-blueprint-route-conflict

Also available as: JSON · Markdown · 中文
80%Fix Rate
86%Confidence
0Evidence
2025-01-05First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3.9 active
3.10 active

Root Cause

Flask 蓝图中的路由端点名称冲突,两个路由使用了相同的端点名

generic

中文

Flask 蓝图中的路由端点名称冲突,两个路由使用了相同的端点名

Workarounds

  1. 95% success 为每个路由指定唯一的端点名
    @blueprint.route('/index', endpoint='main_index')
    def index():
        pass
  2. 90% success 使用蓝图名称作为前缀
    blueprint = Blueprint('main', __name__, url_prefix='/main')

Dead Ends

Common approaches that don't work:

  1. 删除其中一个蓝图但保留路由 70% fail

    功能丢失,且根本问题未解决

  2. 使用相同的函数名但不同蓝图 80% fail

    端点名仍然可能冲突