python
config_error
ai_generated
true
HTTPException: 404 Not Found: /static/style.css
ID: python/starlette-static-file-not-found
80%Fix Rate
85%Confidence
0Evidence
2025-02-10First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.10 | active | — | — | — |
| 3.11 | active | — | — | — |
Root Cause
Starlette 静态文件目录配置错误或文件不存在
generic中文
Starlette 静态文件目录配置错误或文件不存在
Workarounds
-
95% success 挂载静态文件目录
from starlette.staticfiles import StaticFiles app.mount('/static', StaticFiles(directory='static'), name='static') -
90% success 检查文件路径和权限
ls -la static/style.css chmod 644 static/style.css
Dead Ends
Common approaches that don't work:
-
将静态文件放在根目录并直接访问
90% fail
Starlette 不自动提供文件服务
-
使用 Flask 的静态文件方式
80% fail
Starlette 配置语法不同