4

'heroku local' can not find static files, but 'python manage.py runserver' finds the static files without issue. Can you please help me troubleshoot this issue?

settings.py reads:

PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
STATIC_ROOT = os.path.join(PROJECT_ROOT, 'static')
STATIC_URL = '/static/'
STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'

I run collectstatic and the static files are copied to STATIC_ROOT:

python manage.py collectstatic

manage.py runserver' finds the static files without issue:

python manage.py runserver

While 'heroku local' returns a warning 'not found':

11:52:04 AM web.1 |  [19/May/2016 10:52:04] WARNING [django.request:170] Not Found: /static/admin/css/base.css
11:52:04 AM web.1 |  [19/May/2016 10:52:04] WARNING [django.request:170] Not Found: /static/admin/css/base.css
11:52:04 AM web.1 |  [19/May/2016 10:52:04] WARNING [django.request:170] Not Found: /static/admin/css/login.css
11:52:04 AM web.1 |  [19/May/2016 10:52:04] WARNING [django.request:170] Not Found: /static/admin/css/login.css

Not sure what's happening here. Both 'heroku local' and 'manage.py runserver' should see the static files.

Note: I am using Django==1.8.2 and settings.py contains:

import os
import dj_database_url

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

SECRET_KEY = 'secretkey'

DEBUG = True

ALLOWED_HOSTS = []

INSTALLED_APPS = (
    # 'django.contrib.sites',
    'django.contrib.admin',
    'registration',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'dbbackup',
    'listable',
    'rest_framework',
    'bootstrap3',
    'django_crontab',
)

ACCOUNT_ACTIVATION_DAYS = 7 # One-week activation window; you may, of course, use a different value.
REGISTRATION_AUTO_LOGIN = True # Automatically log the user in.

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'django.middleware.security.SecurityMiddleware',
)

ROOT_URLCONF = 'track.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates')],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'track.wsgi.application'

LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True

FIXTURE_DIRS = (
    os.path.join(BASE_DIR, 'fixtures'),
)

MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = 'media/'

REST_FRAMEWORK = {
    # Use Django's standard `django.contrib.auth` permissions,
    # or allow read-only access for unauthenticated users.
    'DEFAULT_PERMISSION_CLASSES': [
        'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly'
    ],
    'DEFAULT_PARSER_CLASSES': (
        'rest_framework_xml.parsers.XMLParser',
    ),
    'DEFAULT_RENDERER_CLASSES': (
        'rest_framework_xml.renderers.XMLRenderer',
    ),
}

DATABASES = {'default' : dj_database_url.config(default='postgres://testuser:testpw@localhost:5432/testdb')}

STATIC_ROOT = os.path.join(PROJECT_ROOT, 'static')
STATIC_URL = '/static/'
STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'),
)

STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'

BOOTSTRAP3 = {
    'include_jquery': True,
}
Ajax
  • 1,418
  • 2
  • 17
  • 38

2 Answers2

10

The solution that works for me (after 24 hours+):

1) install the most recent stable version of whitenoise (I was working from an old example, which required whitenoise==2.0.6)

2) make sure you add whitenoise to MIDDLEWARE_CLASSES:

MIDDLEWARE_CLASSES = (
    'whitenoise.middleware.WhiteNoiseMiddleware',
)

Note: adding 'whitenoise.middleware.WhiteNoiseMiddleware' to the middleware class when using whitenoise==2.0.6 will throw an error. You will need to upgrade to the latest stable version (currently whitenoise==3.1)

Ajax
  • 1,418
  • 2
  • 17
  • 38
0

I am going to assume these admin files are the ones from the Django admin app. Without seeing your project, my best guesses for where you should troubleshoot next are:

1) Check that django.contrib.admin is in your INSTALLED_APPS.

2) Are you changing the DEFAULT_FILE_STORAGE setting? This will interfere with the STATICFILES_FINDERS potentially.

3) Check all of the static files settings, if you are overriding any of them, make sure there are no caveats.

If you post your entire settings.py file, I would have a much better shot at debugging your issue.

  • Thank you @miketheredherring, yes the admin files are from the Django admin app. Yes, django.contrib.admin is included in INSTALLED_APPS. I have not changed DEFAULT_FILE_STORAGE. I have added the contents of settings.py above. – Ajax May 19 '16 at 13:17