python
config_error
ai_generated
true
断言错误:路径/items与现有路由冲突。
AssertionError: Path /items conflicts with existing route
ID: python/starlette-route-duplicate
80%修复率
83%置信度
0证据数
2024-11-20首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.x | active | — | — | — |
根因分析
在Starlette应用中定义了多个相同路径的路由,导致冲突。
English
在Starlette应用中定义了多个相同路径的路由,导致冲突。
解决方案
-
95% 成功率
合并路由或使用不同路径: @app.route("/items") async def list_items(request): ... @app.route("/items/{item_id}") async def get_item(request): ... -
90% 成功率
使用路由前缀: app = Starlette(routes=[ Route("/api/items", endpoint=...), Route("/api/items/{id}", endpoint=...) ])
无效尝试
常见但无效的做法:
-
60% 失败
尝试使用不同的方法(GET/POST)但路径相同,仍会冲突。
-
80% 失败
忽略冲突,但路由匹配可能意外。