python
config_error
ai_generated
true
FileNotFoundError: [Errno 2] No such file or directory: 'static/style.css'
ID: python/starlette-missing-static-files
80%Fix Rate
85%Confidence
0Evidence
2024-12-15First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.x | active | — | — | — |
Root Cause
Starlette static file mount expects the directory to exist; if the file is missing or path is incorrect, this error occurs.
generic中文
Starlette 静态文件挂载要求目录存在;如果文件丢失或路径错误,则会发生此错误。
Workarounds
-
100% success Create the static directory and place files
mkdir -p static # place style.css in static/
-
95% success Mount static files with correct path
from starlette.staticfiles import StaticFiles app.mount('/static', StaticFiles(directory='static'), name='static')
Dead Ends
Common approaches that don't work:
-
Using a relative path that doesn't exist
90% fail
The path must be absolute or relative to the current working directory.
-
Not mounting the static files at all
100% fail
Static files won't be served.