两个路由的 URL 一样会怎样?endpoint 重名会怎样?应用和蓝图抢同一个地址谁赢?这篇把几种冲突都造出来,并给出启动时检查的办法。
同名函数 → AssertionError: View function mapping is overwriting an existing endpoint function: page 同一个函数对象用同一个 endpoint 注册第二个 URL → 允许(同一函数)
上一篇:OPTIONS 与 HEAD 自动处理;下一篇:Blueprint 路由注册;匹配优先级:URL Rule 与路由匹配顺序。
GET /x → first | 规则列表: [('/x', 'first'), ('/x', 'second')]先注册应用路由、后注册蓝图 → GET /hello: from app 先注册蓝图、后注册应用路由 → GET /hello: from bp
第二次注册同名蓝图 → ValueError: The name 'multi' is already registered for this blueprint. Use 'name=' to provide a unique name.
加 name="multi_v2" 后: {'/v1/ping': 200, '/v2/ping': 200} | endpoints: ['multi.ping', 'multi_v2.ping'] {'/about': 'about', '/api/users': 'users', '/api/x': 'catch:api/x', '/zzz/yyy': 'catch:zzz/yyy'} 冲突检查结果: [('/x', 'GET', 'x1', 'x3')]
(/u/<int:i> 与 /u/<name> 参数名不同、归一化后模式也不同,没有被报出来;这个简化脚本只能发现「模式与方法完全相同」的冲突)--sort endpoint → 端点顺序 ['alpha', 'alpha_post', 'static', 'zeta'] --sort rule → 端点顺序 ['alpha', 'alpha_post', 'zeta', 'static'] --sort methods → 端点顺序 ['static', 'zeta', 'alpha', 'alpha_post']