Reputation: 19
I can't load images and css files in django, although everything seems to be fine in settings.py and in the home.html file itself... what can be a problem here?
In the static folder there are template
, css
and image
folders.
HTML:
{% load staticfiles %}
<link rel="stylesheet" type="text/css" href="{% static 'css/main.css' %}">
<title>Main Page</title>
settings.py:
# Static files (CSS, JavaScript, Images)
MEDIA_ROOT = os.path.join(BASE_DIR, "/media")
#MEDIA_URL = ''
#STATIC_ROOT = os.path.join(BASE_DIR, "static")
STATICFILES_DIRS = [
os.path.join(BASE_DIR, "/static")
]
STATIC_URL = "/static/"
Unfortunately, it looks like this:
Upvotes: 0
Views: 277
Reputation: 9634
django.contrib.staticfiles
is not included in your INSTALLED_APPS.
Your settings.py
should look like this (in INSTALLED APPS)
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.sites',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
without that static files won't work even if everything else is setup properly because to django it's not installed even though it is (Technically).
Upvotes: 1