From 3c6898b3f6f907a84264ec6566442efeedf6f2d7 Mon Sep 17 00:00:00 2001 From: Trung Dong Huynh Date: Sun, 8 May 2016 11:55:32 +0100 Subject: [PATCH] Updated whitenoise configuration to match changes in version 3.0 (see http://whitenoise.evans.io/en/stable/changelog.html) --- .../config/settings/production.py | 16 +++++++++++----- {{cookiecutter.project_slug}}/config/wsgi.py | 9 --------- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/{{cookiecutter.project_slug}}/config/settings/production.py b/{{cookiecutter.project_slug}}/config/settings/production.py index f038ac35..8baeebd8 100644 --- a/{{cookiecutter.project_slug}}/config/settings/production.py +++ b/{{cookiecutter.project_slug}}/config/settings/production.py @@ -44,17 +44,23 @@ INSTALLED_APPS += ('raven.contrib.django.raven_compat', ) SECURITY_MIDDLEWARE = ( 'djangosecure.middleware.SecurityMiddleware', ) +{% if cookiecutter.use_whitenoise == 'y' -%} +# Use Whitenoise to serve static files +# See: https://whitenoise.readthedocs.org/ +WHITENOISE_MIDDLEWARE = ( + 'whitenoise.middleware.WhiteNoiseMiddleware', +) +MIDDLEWARE_CLASSES = WHITENOISE_MIDDLEWARE + MIDDLEWARE_CLASSES +{%- endif %} {% if cookiecutter.use_sentry == 'y' -%} RAVEN_MIDDLEWARE = ('raven.contrib.django.raven_compat.middleware.Sentry404CatchMiddleware', 'raven.contrib.django.raven_compat.middleware.SentryResponseErrorIdMiddleware',) -MIDDLEWARE_CLASSES = SECURITY_MIDDLEWARE + \ - RAVEN_MIDDLEWARE + MIDDLEWARE_CLASSES -{% else %} +MIDDLEWARE_CLASSES = RAVEN_MIDDLEWARE + MIDDLEWARE_CLASSES +{%- endif %} # Make sure djangosecure.middleware.SecurityMiddleware is listed first MIDDLEWARE_CLASSES = SECURITY_MIDDLEWARE + MIDDLEWARE_CLASSES -{%- endif %} {% if cookiecutter.use_opbeat == 'y' -%} # opbeat integration # See https://opbeat.com/languages/django/ @@ -132,7 +138,7 @@ MEDIA_URL = 'https://s3.amazonaws.com/%s/media/' % AWS_STORAGE_BUCKET_NAME # Static Assets # ------------------------ {% if cookiecutter.use_whitenoise == 'y' -%} -STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage' +STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage' {% else %} STATIC_URL = 'https://s3.amazonaws.com/%s/static/' % AWS_STORAGE_BUCKET_NAME STATICFILES_STORAGE = 'config.settings.production.StaticRootS3BotoStorage' diff --git a/{{cookiecutter.project_slug}}/config/wsgi.py b/{{cookiecutter.project_slug}}/config/wsgi.py index 7ec57352..4790b1b5 100644 --- a/{{cookiecutter.project_slug}}/config/wsgi.py +++ b/{{cookiecutter.project_slug}}/config/wsgi.py @@ -21,9 +21,6 @@ if os.environ.get('DJANGO_SETTINGS_MODULE') == 'config.settings.production': newrelic.agent.initialize() {%- endif %} from django.core.wsgi import get_wsgi_application -{% if cookiecutter.use_whitenoise == 'y' -%} -from whitenoise.django import DjangoWhiteNoise -{%- endif %} {% if cookiecutter.use_sentry == 'y' -%} if os.environ.get('DJANGO_SETTINGS_MODULE') == 'config.settings.production': from raven.contrib.django.raven_compat.middleware.wsgi import Sentry @@ -39,12 +36,6 @@ os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.production") # file. This includes Django's development server, if the WSGI_APPLICATION # setting points here. application = get_wsgi_application() - -{% if cookiecutter.use_whitenoise == 'y' -%} -# Use Whitenoise to serve static files -# See: https://whitenoise.readthedocs.org/ -application = DjangoWhiteNoise(application) -{%- endif %} {% if cookiecutter.use_sentry == 'y' -%} if os.environ.get('DJANGO_SETTINGS_MODULE') == 'config.settings.production': application = Sentry(application)