python
config_error
ai_generated
true
断言错误:路由应为字符串或 pathlib.Path
AssertionError: Route should be a string or a pathlib.Path
ID: python/starlette-route-order
80%修复率
82%置信度
0证据数
2024-07-11首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.x | active | — | — | — |
根因分析
在 Starlette 中定义了重复的路由,导致路由匹配混乱,或路由路径格式错误。
English
在 Starlette 中定义了重复的路由,导致路由匹配混乱,或路由路径格式错误。
解决方案
-
90% 成功率
添加路由时使用 '/path' 格式,例如 app.add_route('/home', home_page) -
70% 成功率
from pathlib import Path; app.add_route(Path('/home'), home_page)
无效尝试
常见但无效的做法:
-
80% 失败
路由必须是字符串路径,否则无法匹配。
-
100% 失败
断言错误会导致应用启动失败。