python config_error ai_generated true

AssertionError: Route should be a string or a pathlib.Path

ID: python/starlette-route-order

Also available as: JSON · Markdown · 中文
80%Fix Rate
82%Confidence
0Evidence
2024-07-11First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3.x active

Root Cause

在 Starlette 中定义了重复的路由,导致路由匹配混乱,或路由路径格式错误。

generic

中文

在 Starlette 中定义了重复的路由,导致路由匹配混乱,或路由路径格式错误。

Workarounds

  1. 90% success
    添加路由时使用 '/path' 格式,例如 app.add_route('/home', home_page)
  2. 70% success
    from pathlib import Path; app.add_route(Path('/home'), home_page)

Dead Ends

Common approaches that don't work:

  1. 80% fail

    路由必须是字符串路径,否则无法匹配。

  2. 100% fail

    断言错误会导致应用启动失败。