1

I've already went through the thread here:

https://stackoverflow.com/questions/15641603/django-get-css-returns-404

but the solutions did not help.

The .css file is loaded from within the base.html, the important part looks like this

<link href="{% static 'css/starter-template.css' %}" rel="stylesheet">

The exact info given by pycharm concerning this problem is this:

"GET /static/css/starter-template.css HTTP/1.1" 404 1685

The path for the css file is correct as well. Which makes me wonder: If the path is correct, then why do I get a 404? How can I fix this?

edit: As requested, this is what the folder structure looks like:

https://i.sli.mg/2MwZM4.png

starter-template.css is the file which causes the 404. I'm referencing it in base.html

user2765654
  • 160
  • 6

1 Answers1

2

Hmm... I believe the issue is that your django project isn't able to discover the static directory you've created inside of the templates directory.

By default, Django will search for static assets inside of a folder named "static" inside of each folder in INSTALLED_APPS in settings.py. It will not look for assets anywhere else unless explicitly told to do so.

The setting for doing so is "STATICFILES_DIRS" and the relevant section of the documentation is here: https://docs.djangoproject.com/en/1.9/ref/settings/#std:setting-STATICFILES_DIRS

You can use an absolute path to your static directory within your settings.py file, eg:

STATICFILES_DIRS = [
  '/home/rtownley/path_to_project/static/',
]

Or, if os is imported and BASE_DIR is set (both should be the case by default in settings.py)

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

Note: If you're not already doing so, you might also now be required to set STATIC_ROOT if you're specifying other locations (not entirely sure if this is the case) but if so, you can set it in settings.py to something like

STATIC_ROOT = os.path.join(BASE_DIR, "STATICROOT")
Robert Townley
  • 3,414
  • 3
  • 28
  • 54