# 断言错误：重复的路由：/items

- **ID:** `python/fastapi-duplicate-route`
- **领域:** python
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

FastAPI 不允许为同一 HTTP 方法和路径定义两个路由处理程序。

## 版本兼容性

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

## 解决方案

1. **Remove or comment out the duplicate route** (100% 成功率)
   ```
   # Remove the second @app.get('/items') decorator
   ```
2. **Use different HTTP methods or paths** (100% 成功率)
   ```
   @app.get('/items')
def list_items(): ...
@app.post('/items')
def create_item(): ...
   ```

## 无效尝试

- **Renaming one function without changing the route** — The route path and method are still duplicated. (100% 失败率)
- **Adding a prefix to one route manually** — If the prefix doesn't change the full path, duplication persists. (80% 失败率)
