Django -- Can't get static CSS files to load
Read this carefully: https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/
Is django.contrib.staticfiles
in your INSTALLED_APPS
in settings.py
?
Is DEBUG=False
? If so, you need to call runserver
with the --insecure
parameter:
python manage.py runserver --insecure
collectstatic
has no bearing on serving files via the development server. It is for collecting the static files in one location STATIC_ROOT
for your web server to find them. In fact, running collectstatic
with your STATIC_ROOT
set to a path in STATICFILES_DIRS
is a bad idea. You should double-check to make sure your CSS files even exist now.
For recent releases of Django, You have to configure static files in settings.py
as,
STATIC_URL = '/static/' # the path in url
STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static"),
]
and use it with static template tag,
{% load static %}
<link rel="stylesheet" href="{% static 'css/bootstrap.css' %}">
Another simple thing to try is to stop, and then restart the server e.g.
$ python manage.py runserver
I looked into the other answers, but restarting the server worked for me.