'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,
}
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With