I've been struggling to get my page to load the style.css file correctly.
I made sure to add the path for STATICFILES_DIRS
as shown below,
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static"),
]
STATIC_ROOT = os.path.join(BASE_DIR, "static_cdn")
index.html
{% load staticfiles %}
`<link rel='stylesheet' href='{% static "css/style.css" %}' type='text/css'>`
After running collectstatic
, it collected the style.css
successfully.
However, when I inspect the element and try to open a link to style.css
(http://127.0.0.1:8000/static/css/style.css)
, it shows a message saying not found
.
I even attempted to hard-code the path to style.css
without any success.
In a separate project, I followed the same steps and the style.css
loaded perfectly fine, opening the link displays the CSS code.
I am at a loss here. Any help would be greatly appreciated.
Edit
setting.py template settings:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
Directory structure:
|myproject
|----- MyApp/
|---- myProject/
|---- static/
|---- static_cdn/
|----manage.py