I am trying to load the style.css on my page.
I've added the path for STATICFILES_DIRS
like 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'>`
When I ran the collectstatic
and it collected the style.css
.
When I do inspect element and open a link of style.css
(http://127.0.0.1:8000/static/css/style.css)
, it gives me not found
message.
I tried hard-coding the path to style.css
but, no luck.
I created the another sample project and followed the same steps and style.css
loaded successfully.
When I do inspect element and open a link of style.css
, it shows me html code.
I am really helpless. Any help is really 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
1) Select the folder(s) where you want the static assets from where you want them to be collected:
2) Select the folder where you want the static assets to be collected:
3) Run
python manage.py collectstatic
Note:
In
STATICFILES_DIRS
you can add any path you want, it can be an absolute path.collectstatic
will place the static in yourSTATIC_ROOT
.