Resolving an issue that static files can’t be reached (i.e., files not found, 404) when using Django running on a NameCheap shared machine.
I bumped into an issue when trying to set up a Django + React environment by following this tutorial on my NameCheap space.
No matter how I tried configuring Django’s
Nothing was mentioned in the tutorial for any potential issues like this, until I found an answer in this post.
It turns out to be a WSGI problem and it has nothing to do with Django’s or React’s configurations.
By making changes in my
import os from django.conf import settings from django.contrib.staticfiles.handlers import StaticFilesHandler from django.core.wsgi import get_wsgi_application os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'project.settings') if settings.DEBUG: application = StaticFilesHandler(get_wsgi_application()) else: application = get_wsgi_application()
where you need to replace the 'project.settings'
string with your project name’s.
References
- https://umar-yusuf.blogspot.com/2020/04/setting-up-django-project-and-app-on.html
- https://www.valentinog.com/blog/drf/
- https://stackoverflow.com/questions/6014663/django-static-file-not-found
Was this post helpful?
Let us know if you liked the post. That’s the only way we can improve.