python
config_error
ai_generated
true
AssertionError: Route should be a string or a pathlib.Path
ID: python/starlette-route-order
80%Fix Rate
82%Confidence
0Evidence
2024-07-11First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.x | active | — | — | — |
Root Cause
在 Starlette 中定义了重复的路由,导致路由匹配混乱,或路由路径格式错误。
generic中文
在 Starlette 中定义了重复的路由,导致路由匹配混乱,或路由路径格式错误。
Workarounds
-
90% success
添加路由时使用 '/path' 格式,例如 app.add_route('/home', home_page) -
70% success
from pathlib import Path; app.add_route(Path('/home'), home_page)
Dead Ends
Common approaches that don't work:
-
80% fail
路由必须是字符串路径,否则无法匹配。
-
100% fail
断言错误会导致应用启动失败。