Repository: cookiecutter/cookiecutter-django

Issue:
Add support for whitenoise
Sometimes we just don't need the weight of AWS for media assets. I think this should be an option in the cookiecutter.json file.



Discussion:
+1

+1 for this. Sometimes Whitenoise is just good enough.


Resolving patch:
diff --git a/{{cookiecutter.repo_name}}/config/settings/production.py b/{{cookiecutter.repo_name}}/config/settings/production.py
--- a/{{cookiecutter.repo_name}}/config/settings/production.py
+++ b/{{cookiecutter.repo_name}}/config/settings/production.py
@@ -55,12 +55,13 @@
 
 # STORAGE CONFIGURATION
 # ------------------------------------------------------------------------------
+# Uploaded Media Files
+# ------------------------
 # See: http://django-storages.readthedocs.org/en/latest/index.html
 INSTALLED_APPS += (
     'storages',
 )
-
-STATICFILES_STORAGE = DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
+DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
 
 AWS_ACCESS_KEY_ID = env('DJANGO_AWS_ACCESS_KEY_ID')
 AWS_SECRET_ACCESS_KEY = env('DJANGO_AWS_SECRET_ACCESS_KEY')
@@ -69,11 +70,6 @@
 AWS_QUERYSTRING_AUTH = False
 AWS_S3_CALLING_FORMAT = OrdinaryCallingFormat()
 
-# See: https://github.com/antonagestam/collectfast
-# For Django 1.7+, 'collectfast' should come before 'django.contrib.staticfiles'
-AWS_PRELOAD_METADATA = True
-INSTALLED_APPS = ('collectfast', ) + INSTALLED_APPS
-
 # AWS cache settings, don't change unless you know what you're doing:
 AWS_EXPIRY = 60 * 60 * 24 * 7
 
@@ -85,8 +81,22 @@
         AWS_EXPIRY, AWS_EXPIRY))
 }
 
-# See: https://docs.djangoproject.com/en/dev/ref/settings/#static-url
-STATIC_URL = 'https://s3.amazonaws.com/%s/' % AWS_STORAGE_BUCKET_NAME
+# URL that handles the media served from MEDIA_ROOT, used for managing stored files.
+MEDIA_URL = 'https://s3.amazonaws.com/%s/' % AWS_STORAGE_BUCKET_NAME
+
+# Static Assests
+# ------------------------
+{% if cookiecutter.use_whitenoise == 'y' -%}
+STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'
+{% else %}
+STATICFILES_STORAGE = DEFAULT_FILE_STORAGE
+STATIC_URL = MEDIA_URL
+
+# See: https://github.com/antonagestam/collectfast
+# For Django 1.7+, 'collectfast' should come before 'django.contrib.staticfiles'
+AWS_PRELOAD_METADATA = True
+INSTALLED_APPS = ('collectfast', ) + INSTALLED_APPS
+{%- endif %}
 
 # EMAIL
 # ------------------------------------------------------------------------------
diff --git a/{{cookiecutter.repo_name}}/config/wsgi.py b/{{cookiecutter.repo_name}}/config/wsgi.py
--- a/{{cookiecutter.repo_name}}/config/wsgi.py
+++ b/{{cookiecutter.repo_name}}/config/wsgi.py
@@ -15,6 +15,11 @@
 """
 import os
 
+from django.core.wsgi import get_wsgi_application
+{% if cookiecutter.use_whitenoise == 'y' -%}
+from whitenoise.django import DjangoWhiteNoise
+{%- endif %}
+
 # We defer to a DJANGO_SETTINGS_MODULE already in the environment. This breaks
 # if running multiple sites in the same mod_wsgi process. To fix this, use
 # mod_wsgi daemon mode with each site in its own daemon process, or use
@@ -24,9 +29,14 @@
 # This application object is used by any WSGI server configured to use this
 # file. This includes Django's development server, if the WSGI_APPLICATION
 # setting points here.
-from django.core.wsgi import get_wsgi_application  # noqa
 application = get_wsgi_application()
 
+{% if cookiecutter.use_whitenoise == 'y' -%}
+# Use Whitenoise to serve static files
+# See: https://whitenoise.readthedocs.org/
+application = DjangoWhiteNoise(application)
+{%- endif %}
+
 # Apply WSGI middleware here.
 # from helloworld.wsgi import HelloWorldApplication
 # application = HelloWorldApplication(application)


Test patch: