martinb
martinb

Reputation: 175

Django unable to find css file in STATICFILES_DIR

My base.html cannot find base.css. I configured my settings.py file to point to where the css file resides but still get 404.

I have the following at bottom of settings.py

STATIC_URL = '/static/'
STATICFILES_DIR = [os.path.join(BASE_DIR, 'static')]

File system tree:

.
├── blog
│   ├── admin.py
│   ├── apps.py
│   ├── __init__.py
│   ├── migrations
│   │   ├── 0001_initial.py
│   │   └── __init__.py
│   ├── models.py
│   ├── tests.py
│   ├── urls.py
│   └── views.py
├── blog_project
│   ├── __init__.py
│   ├── settings.py
│   ├── urls.py
│   └── wsgi.py
├── db.sqlite3
├── manage.py
├── Pipfile
├── Pipfile.lock
├── static
│   └── css
│       └── base.css
└── templates
    ├── base.html
    └── home.html

Thank you.

Upvotes: 0

Views: 44

Answers (2)

Sanjay Bisht
Sanjay Bisht

Reputation: 86

You are missing STATIC_ROOT.

STATIC_ROOT = os.path.join(BASE_DIR, 'static')

Upvotes: 1

rahul.m
rahul.m

Reputation: 5854

try this

in settings.py

STATIC_ROOT = BASE_DIR + '/static/'

in urls.py

from django.conf import settings

if settings.DEBUG:
    urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

hope it helps

Upvotes: 1

Related Questions