# Starlette HTTP异常：404 未找到

- **ID:** `python/starlette-http-exception-404`
- **领域:** python
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

请求的URL没有定义路由，或由于路由不匹配导致URL错误。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.x | active | — | — |

## 解决方案

1. **** (90% 成功率)
   ```
   Check app.routes to see registered routes and ensure the path matches exactly, including trailing slashes.
   ```
2. **** (80% 成功率)
   ```
   Add a catch-all route: @app.route('/{path:path}')\nasync def catch_all(request):\n    raise HTTPException(status_code=404)
   ```

## 无效尝试

- **** — Catching all HTTPExceptions and returning a custom page can mask other errors like 500s. (50% 失败率)
- **** — Using regex patterns incorrectly in route paths can cause unexpected 404s. (70% 失败率)
