Adding a static file directory to override CSS in Django
Question
I'm trying to figure out why I can't override base.css
in Django.
In settings.py
I have:
STATIC_URL = "/site_media/static/"
And in site_base.html
:
<link rel="stylesheet" href="{{ STATIC_URL }}pinax/css/base.css" />
And I have customized the file located in /site_media/static/pinax/css/base.css
. But instead of reading the file from here, it is reading it from my python/site-packages/pinax
directory still. And in the same site_base.html
file I am able to override an image which is in the /site_media_static/pinax/images/
folder, which seems odd that I can overwrite the image but not the CSS file.
Any idea what I'm doing wrong?
Solution
The STATIC_URL
is the URL static files are served from, not the directory where they are stored.
You need to add the directory containing your static files to STATICFILES_DIRS
or put your static files in an app's static
subdir.
See the docs for the Django staticfiles app.
OTHER TIPS
STATIC_ROOT
(which is referenced by STATIC_URL
) should not be modified manually, it's being populated by collectstatic
command from ann apps static dirs and STATICFILES_DIRS
. In Django's dev server there is also a helper which allows accessing static file directly from the source, that allows easier debugging of JS and CSS.
In your case you can try putting updated file somewhere inside STATICFILES_DIRS
. Also, take a look at STATICFILES_FINDERS
which can change ordering for static files finders to set which one will have the priority.