There are several things to consider here and I am not sure which applies because I'm working on pure assumptions of your situation without knowing:
- What is
BASE_DIR
set to
- Have you run
manage.py collectstatic
- what is your server setup or are you just working off the django development server?
- Where are the files you're trying to link to actually placed
Anyway here is some info I hope will be useful. I will break down how the settings files relates to your template file and hopefully that will help you debug your problem.
STATIC_URL = '/static/'
-- > the value of this is what will be appended to the static file you are linking in your template. It is the relative url after your domain name. So {% static 'css/styles.css' %}
will be rendered as /static/css/styles.css
in your html page when it is loaded.
STATIC_ROOT
is the absolute path of where your files are located on disk. It tells django where to place all static files collected from your apps when you run manage.py collectstatic
see here for details.
STATICFILES_DIRS
tells django where to find project static files. By default Django will look for a static
directory in each registered app and collect the files in there and place then in your STATIC_ROOT
folder. If you want to put static files in a different directory in your project and you want django to know about it then you list those paths in this config variable.
With your code:
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR,'static','static_root')
STATICFILES_DIRS = [
os.path.join(BASE_DIR,'static','static_dirs')
]
{% static 'css/cover.css' %}
is translating to /static/css/cover.css
, your telling django the root directory to collect static files is <your BASE_DIR>/static/static_root
so here you can see that there might be a miss match in locations. Again I don't know if you ran collectstatic
. your STATICFILES_DIR
is just going to look for static files in <your BASE_DIR>/static/static_root
to then put them in <your BASE_DIR>/static/static_root
... if that makes sense.