Django – Static Files from App Directories

Question:

In a development environment, I’d like to use static files from the app directories.

#settings.py

SITE_ROOT = os.path.dirname(os.path.realpath(__file__))
STATIC_ROOT = (os.path.join(SITE_ROOT, 'static_files/'))
STATIC_URL = '/static/'
STATICFILES_DIRS = (
  os.path.join(SITE_ROOT, 'static/'),
)
STATICFILES_FINDERS = (
  'django.contrib.staticfiles.finders.FileSystemFinder',
  'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)
TEMPLATE_CONTEXT_PROCESSORS = (
#...
  'django.core.context_processors.static',
#...
)
INSTALLED_APPS = (
#...
  'django.contrib.staticfiles',
#...
)

I can find my static file if located in /static/css/file.css but not if in an_app/static/css/file.css.

Asked By: Pierre de LESPINAY

||

Answers:

Check the value of STATIC_ROOT and STATICFILES_DIRS.
Add a print in your setting file.

Answered By: VGE

Ok I found the problem, I made an oversight that was not visible in my question. I was searching into in static/js, static/flash, static/css, static/images and put the files directly into app/static so they were not found.

Answered By: Pierre de LESPINAY

Try adding your apps to the setting.py file if you haven’t done it, into a list called ‘INSTALLED_APPS’, individual app there can be named like ‘app_name.app.App_name.Config’. More detailed here. Solved a problem for me.

Answered By: George Kokkin