python
config_error
ai_generated
true
HTTP 异常:404 未找到:/static/style.css
HTTPException: 404 Not Found: /static/style.css
ID: python/starlette-static-file-not-found
80%修复率
85%置信度
0证据数
2025-02-10首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.10 | active | — | — | — |
| 3.11 | active | — | — | — |
根因分析
Starlette 静态文件目录配置错误或文件不存在
English
Starlette 静态文件目录配置错误或文件不存在
解决方案
-
95% 成功率 挂载静态文件目录
from starlette.staticfiles import StaticFiles app.mount('/static', StaticFiles(directory='static'), name='static') -
90% 成功率 检查文件路径和权限
ls -la static/style.css chmod 644 static/style.css
无效尝试
常见但无效的做法:
-
将静态文件放在根目录并直接访问
90% 失败
Starlette 不自动提供文件服务
-
使用 Flask 的静态文件方式
80% 失败
Starlette 配置语法不同