I keep getting a 404 error when django is looking for static files.
settings.py
STATIC_ROOT = os.path.join(BASE_DIR, 'business', 'static_cdn')
STATIC_URL = '/static_cdn/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'business', 'static'),
]
project tree structure of app
- business
-- migrations
--- ....
-- static_cdn
--- business
---- main.css
---- scripts.js
-- templates
--- business
---- base.html
---- home.html
-- templatetags
--- ...
-- __init__.py
-- admin.py
-- apps.py
-- models.py
-- tests.py
-- urls.py
-- views.py
Error
[29/Jul/2019 13:09:45] "GET / HTTP/1.1" 200 12670
[29/Jul/2019 13:09:45] "GET /static_cdn/business/main.css HTTP/1.1" 404 77
[29/Jul/2019 13:09:45] "GET /static_cdn/business/scripts.js HTTP/1.1" 404 77
I also link to static files like {% static 'business/main.css' %}
and I do have {% load static %}
at the top of my document.
Why isn't django able to find the static files? The error says it is looking in the correct place but it is returning 404 error.
If you need anything else, you can look at my code
Note:
I think that django isn't able to read this files but I don't know why... Collectstatic puts all static_cdn/
into static/
in same app dir.
You probably have set DEBUG to False. If and only if, you are in development environment , set DEBUG to True. If you are planning for production, do collectstatic first and do appropriate changes in the settings.py and set DEBUG back to False. See the Django doc and your production server doc. Also don't forget to restart the server. Best wishes.