joel goldstick joel goldstick - 1 year ago 225
Python Question

Not finding static files django 1.9 gunicorn

I am on my way to deployment but when I switched to gunicorn from dev server my static files aren't being found. I ran collectstatic, and the files have been collected.

note in my settings file I print the path to my static files. This is from my gunicorn log:

Not Found: /static/admin/css/base.css
Not Found: /static/admin/css/dashboard.css

Here is my settings file. I have updated correctly (I hope) settings from the original django 1.6 version.

Django settings for baseball_stats project.

For more information on this file, see

For the full list of settings and their values, see

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os

# this for reading environment variables for private values (secret_key, etc)
# copy this to .bashrc or if using virtualvenvwrapper to bin/postactivate script
# EXPORT VARIABLE=thevaluegoeshere
import get_env_variable

BASE_DIR = os.path.dirname(os.path.dirname(__file__))

# Most recent year for statistics

# Quick-start development settings - unsuitable for production
# See

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '-s*2+cq_niwa&*b%9(0w6$w!*9%d98oe7r6=+m0v+8(^&!10b6'
SECRET_KEY = get_env_variable.get_env_variable('SECRET_KEY')

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True



# Application definition

# 'debug_toolbar',
# 'csvimport',


ROOT_URLCONF = 'baseball_stats.urls'

WSGI_APPLICATION = 'baseball_stats.wsgi.application'

# Database

'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',

'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),

# Internationalization


TIME_ZONE = 'America/New_York'

USE_I18N = True

USE_L10N = True

USE_TZ = True

# Static files (CSS, JavaScript, Images)

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, "collect_static")

'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'context_processors': [
'version': 1,
'handlers': {
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'loggers': {
'django.db.backends': {
'level': 'DEBUG',
'handlers': ['console'],

I looked at this: Django Gunicorn not load static files

But my understanding is gunicorn can do static files, it just isn't as efficient as using nginx. I thought I would do this as a first step before setting up nginx

Running ./ findstatic doesn't find my files, so, I am guessing its my settings file, not the server

Answer Source

Third party app

All You need is dj-static package.

pip install dj-static

Configure your static assets in

STATIC_ROOT = 'staticfiles'
STATIC_URL = '/static/'

Then, update your file to use dj-static:

from django.core.wsgi import get_wsgi_application
from dj_static import Cling

application = Cling(get_wsgi_application())

Pure Django

Add to Your

from django.contrib.staticfiles.urls import staticfiles_urlpatterns


urlpatterns += staticfiles_urlpatterns()
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download