1

This is my first Django project. I cannot load CSS files onto my website. i've done everything possible.

Project Directries

firstproject/
  assets/
  static/
    css/
      <CSS files>

Settings.py/ static files

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

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

urls.py

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

HTML file

<link rel="stylesheet" href="{% static 'css/bootstrap-grid.css' %}">
4
  • where is assets folder? STATIC_ROOT points to it. how is BASE_DIR initialized? DEBUG = true or false? Commented Nov 30, 2022 at 20:33
  • Is your link in the head of your HTML file? Commented Nov 30, 2022 at 23:53
  • I forgot to mention assets in the code. but it is there, and DEBUG is set to TRUE. Commented Dec 1, 2022 at 4:45
  • Yes Link in head of HTML file. Commented Dec 1, 2022 at 4:45

1 Answer 1

0

I think you made spelling mistake in staticfilesdirs in settings.py file.

Change this:

STATIC_URL = 'static/'
STATICFILE_DIRS = [ #Here you made spelling mistake. It should be  `STATICFILES_DIRS`
    os.path.join(BASE_DIR, "static")
]

To this:

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

And in link tag just add type="text/css".

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.