[Answered ]-CSS GET returns 404

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")

Leave a comment