python runtime_error ai_generated true

Starlette 路由错误:没有路由匹配路径 "/items/"

starlette.routing.NoMatchFound: No route matches for path "/items/"

ID: python/starlette-routing-path-param-missing

其他格式: JSON · Markdown 中文 · English
80%修复率
84%置信度
0证据数
2025-08-20首次发现

版本兼容性

版本状态引入弃用备注
3.x active

根因分析

请求的 URL 路径与任何定义的路由不匹配,可能是由于尾部斜杠不匹配。

English

The requested URL path doesn't match any defined route, possibly due to trailing slash mismatch.

generic

解决方案

  1. 90% 成功率
    Define the route with optional trailing slash: @app.route('/items/{path:path}') or use redirect_slashes=True
  2. 80% 成功率
    Ensure the client sends the correct path: /items (without trailing slash) if your route is '/items'

无效尝试

常见但无效的做法:

  1. 50% 失败

    If the client doesn't send the slash, it still won't match; you need redirect_slashes=True (default).

  2. 40% 失败

    May hide actual errors; better to define specific routes.