New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
StaticFiles return 404 #1002
Comments
I tried running your code and got the same results as well using the following directory structure, and running the app from the project root:
It looks to be an issue with the starlette/starlette/staticfiles.py Lines 144 to 149 in 6aa7d9e
It is not able to find a common prefix between I was able to serve static files under if (os.path.commonprefix([os.path.realpath(full_path), os.path.realpath(directory)])
!= os.path.realpath(directory)): |
It looks to be already mentioned in this PR: #985 |
Thanks for the input! I have tested a little bit on my Windows 10 Notebook and it seems that StaticFiles return 404 if directory parameter is pathlib class. When you pass the string of correct format (Windows for Windows system) it works:
os.path.* functions work because they return string values, even if their argument is Path:
Most interestingly that there are different results depending on whether directory passed as Path exists or not: |
Resolved in 0.13.6 |
Hi!
I use example from the docs:
The code saved in .py file in a directory which has sub-directory named 'static'.
That sub-directory has file named 'index.html'.
I run app using uvicorn.
The bug:
When I access http://localhost:8000/static/index.html the response is 404 even though that file is present.
I have tried:
The result is still the same.
Is there something else that I should add to my app to make it work? The docs leave the impression that this is all I have to do.
I have Windows OS.
The text was updated successfully, but these errors were encountered: