# INFO: 127.0.0.1:xxxxx - "GET /static/style.css HTTP/1.1" 404 未找到

- **ID:** `python/starlette-static-files-404`
- **领域:** python
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

StaticFiles 挂载的目录相对于进程工作目录不存在，或挂载路径与 URL 前缀不一致。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 0.30+ | active | — | — |

## 解决方案

1. **** (95% 成功率)
   ```
   from pathlib import Path
from fastapi.staticfiles import StaticFiles
BASE = Path(__file__).resolve().parent
app.mount('/static', StaticFiles(directory=BASE / 'static'), name='static')
   ```
2. **** (85% 成功率)
   ```
   assert (BASE / 'static').is_dir(), 'static dir missing'
   ```

## 无效尝试

- **** — Bypasses StaticFiles caching and content-type handling; fragile. (80% 失败率)
- **** — Shadows API routes registered after the mount. (75% 失败率)
