Django cannot find static files. Need a second pair of eyes, I'm going crazy
do the following:
If you are in DEBUG, set STATICFILES_DIRS = ("path/to/static") variable in your settings.py. It should then work only in DEBUG mode.
If you want it to also work in deploy mode, set STATIC_ROOT = ("path/to/static_root") variable in the settings.py. Then, execute
python manage.py collectstatic
and it should also work.
And now, for a better understanding how django manages static files:
Django has some predefined places to look for static files and collect them, you specify where to find them with the STATICFILES_FINDERS in your settings.py. By default, it looks for static folder inside your apps. You can tell Django to look for static files in other parts by setting the STATICFILES_DIRS variable (list or tuple of paths).
In DEBUG mode, staticfiles are picked from this paths (not from the static_root where you collect your files).
When you execute
python manage.py collectstatic
, Django goes through all directories where static files can be found, and places them in your static root. When you run in deploy mode, static files are served from this directory.
PS: What I normally do is to create an app called common and create a static dir inside to place all common css, js for my project (and also for templates). This way, I don't have to specify the STATICFILES_DIRS variable.
Hope it is clear now =).
Change STATIC_ROOT of settings.py, I hope it will work. I face the same problem....
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static')
]
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
Well, just going through the Tutorial, I was stuck with this problem pretty much. Simply restarting the web-service has fixed it. So, if just completing the Tutorial instructions, put a directory static//style.css inside the dir named , while putting
{% load staticfiles %}
<link rel="stylesheet" type="text/css" href="{% static '<your_app_name>/style.css' %}" />
inside head-section of a html-files (for ex., index.html) that should be designed with that css-file.