# AttributeError: 'FastAPI' 对象没有属性 'router'

- **ID:** `python/fastapi-attribute-error-router`
- **领域:** python
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

错误地调用 app.router，或在非应用对象上访问 router 属性的旧 API 模式。

## 版本兼容性

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

## 解决方案

1. **** (94% 成功率)
   ```
   from fastapi import APIRouter
router = APIRouter()
app.include_router(router)
   ```
2. **** (88% 成功率)
   ```
   for r in app.routes:
    print(r.path)
   ```

## 无效尝试

- **** — Attribute name exists but internal structure differs; downstream calls fail. (85% 失败率)
- **** — Reintroduces other incompatibilities and is unsupported. (80% 失败率)
