0
votes

EDIT: I figured out that the CSS file was not being displayed because I copied the link tag pointing to the CSS file from Microsoft Word, so the quotations marks around rel="stylesheet" were not the right type of quotations marks!!

The settings.py file in the project folder defines the STATIC_URL variable as '/static/'

The CSS file is inside the app folder: DjangoProject/shop/static/shop/style.css

The {% load static %} is at the top of the HTML template (if I use "staticfiles" instead of "static", I get an error)

The CSS file is linked using href="{% static 'shop/style.css' %}"

The CSS file loads and is visible when I analyze the "view page source", but the actual CSS is not displayed on the webpage.

What am I doing wrong? I'm using Django version 3.0.7

EDIT:

I've also tried defining the STATICFILES_DIRS in the settings.py file, but that doesn't do anything. Nor does adding the additional code below to the project urls.py file.

STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'static'),
]

.

from django.conf.urls.static import static
from django.contrib.staticfiles.urls import staticfiles_urlpatterns

urlpatterns = [
    #your url patterns
]
urlpatterns += staticfiles_urlpatterns() 

Image of my code

1
Do you have django.contrib.staticfiles inside of your INSTALLED_APPS in settings.py? It would be more beneficial if you included your actual code in stead of an image. - plum 0
Yes, 'django.contrib.staticfiles', is there in the INSTALLED_APPS list. - b0302

1 Answers

1
votes

you have to add

STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'static'),
]

in your settings.py file below STATIC_URL

add bolew code in main urls.py

from django.conf.urls.static import static
from django.contrib.staticfiles.urls import staticfiles_urlpatterns

urlpatterns = [
    #your url patterns
]
urlpatterns += staticfiles_urlpatterns()

and make sure you are hard refreshing the webpage and try restarting server