0

I know there are already several threads on the topic. I've been through most of them (especially all the troubleshooting listed in this one) but I can't figure out my issue.

I am trying to use a Bootstrap template in my Django project, and I'd like to simply start by accessing the files in the /static/ directory. My project directory looks like this :

enter image description here

Whenever I try to load the page http://localhost:8000/static/theme/assets/css/style.css it returns a Page not found error (and obviously no CSS/JS content appears on my index).

Here are my settings:

  • I have debug = True
  • ÌNSTALLED_APPS contains django.contrib.staticfiles
  • settings.py looks like this :
STATIC_URL = "/static/"
STATICFILES_DIRS = (os.path.join(BASE_DIR, "static/"),)

But I still can't access anything from the /static/ directory. I tried to access the CSS and JS files in base.html this way :

{% load static %}
...
<link href="{% static 'theme/assets/css/style.css' %}" rel="stylesheet">

I really have no clue how I could solve this.

Thanks in advance for your help !

allaxim
  • 36
  • 2
  • Is `base.html` properly bound bound with a URL and with a view function via a URL dispatcher ( https://docs.djangoproject.com/en/3.2/topics/http/urls/ ) ? Can you access that file from your browser ? – Tms91 Nov 30 '21 at 14:30

1 Answers1

1

Is base.html properly bound to a URL and to a view function via a URL dispatcher ? Can you access that file from your browser ?

If yes, try to substitute this line

STATICFILES_DIRS = (os.path.join(BASE_DIR, "static/"),)

with this one

STATICFILES_DIRS = (os.path.join(BASE_DIR, "static"),)
Tms91
  • 3,456
  • 6
  • 40
  • 74
  • Well, `index.html` is bound to a URL thanks to `path("", views.index, name="index")` and `base.html` is called inside `index.html` with `{% extends 'base.html' %}`. And I had tried removing the / but no effect sadly – allaxim Nov 30 '21 at 15:05
  • try to put an image in a folder `img` inside `static`, espose it in your `base.html` with `` and see if it appears in your browser – Tms91 Nov 30 '21 at 16:22
  • try to inspect the console logs of your browser – Tms91 Dec 02 '21 at 13:53