[Django]-Why is Django not loading my CSS?

3πŸ‘

βœ…

I think you miss this in urls.py:

from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
    # ... the rest of your URLconf goes here ...
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

This work in dev, in production you must collectstatic with manage.py and serve statics with nginx(or apache).

πŸ‘€Diego Puente

1πŸ‘

for django==2.0.2 none of the urls.py changes are necessary, just get STATIC_URL in settings.py right

πŸ‘€user2584621

0πŸ‘

Run into the same issue, after searching without any solution, I casually pressed Enter in CMD window, and python runserver continued and I found /static/css/blog.css was successfully found.

enter image description here

πŸ‘€NOZUONOHIGH

0πŸ‘

I had the some problem and the solution that works for me was stop the server using CRTL-BREAK and start again. I am using Django v.3.0.7.

πŸ‘€m4u2o

0πŸ‘

If you are not extending from other html file as in your case then the first entry in your html file should be !DOCTYPE html and then the load template tag i.e {%load staticfiles%}.

πŸ‘€user14177528

0πŸ‘

For anyone who this after django removed the import of os in the settings file.

Use STATIC_ROOT = BASE_DIR / 'static' instead of os.path......

Leave a comment