Merge pull request #227 from pydanny/whitenoise-support

feat(static_storage): Add support for whitenoise (optional)
This commit is contained in:
Daniel Greenfeld 2015-04-26 08:46:23 -07:00
commit 91eb30da8c
5 changed files with 46 additions and 14 deletions

View File

@ -31,6 +31,7 @@ Features
* Grunt build for compass and livereload * Grunt build for compass and livereload
* Basic e-mail configurations for send emails via SendGrid_ * Basic e-mail configurations for send emails via SendGrid_
* Media storage using Amazon S3 * Media storage using Amazon S3
* Serve static files from Amazon S3 or Whitenoise_ (optional)
.. _Bootstrap: https://github.com/twbs/bootstrap .. _Bootstrap: https://github.com/twbs/bootstrap
.. _AngularJS: https://github.com/angular/angular.js .. _AngularJS: https://github.com/angular/angular.js
@ -40,6 +41,7 @@ Features
.. _django-avatar: https://github.com/jezdez/django-avatar/ .. _django-avatar: https://github.com/jezdez/django-avatar/
.. _Procfile: https://devcenter.heroku.com/articles/procfile .. _Procfile: https://devcenter.heroku.com/articles/procfile
.. _SendGrid: https://sendgrid.com/ .. _SendGrid: https://sendgrid.com/
.. _Whitenoise: https://whitenoise.readthedocs.org/
Constraints Constraints

View File

@ -8,5 +8,6 @@
"version": "0.1.0", "version": "0.1.0",
"timezone": "UTC", "timezone": "UTC",
"now": "2015/01/13", "now": "2015/01/13",
"year": "{{ cookiecutter.now[:4] }}" "year": "{{ cookiecutter.now[:4] }}",
"use_whitenoise": "y"
} }

View File

@ -55,12 +55,13 @@ INSTALLED_APPS += ("gunicorn", )
# STORAGE CONFIGURATION # STORAGE CONFIGURATION
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Uploaded Media Files
# ------------------------
# See: http://django-storages.readthedocs.org/en/latest/index.html # See: http://django-storages.readthedocs.org/en/latest/index.html
INSTALLED_APPS += ( INSTALLED_APPS += (
'storages', 'storages',
) )
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
STATICFILES_STORAGE = DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
AWS_ACCESS_KEY_ID = env('DJANGO_AWS_ACCESS_KEY_ID') AWS_ACCESS_KEY_ID = env('DJANGO_AWS_ACCESS_KEY_ID')
AWS_SECRET_ACCESS_KEY = env('DJANGO_AWS_SECRET_ACCESS_KEY') AWS_SECRET_ACCESS_KEY = env('DJANGO_AWS_SECRET_ACCESS_KEY')
@ -69,11 +70,6 @@ AWS_AUTO_CREATE_BUCKET = True
AWS_QUERYSTRING_AUTH = False AWS_QUERYSTRING_AUTH = False
AWS_S3_CALLING_FORMAT = OrdinaryCallingFormat() 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 cache settings, don't change unless you know what you're doing:
AWS_EXPIRY = 60 * 60 * 24 * 7 AWS_EXPIRY = 60 * 60 * 24 * 7
@ -85,8 +81,22 @@ AWS_HEADERS = {
AWS_EXPIRY, AWS_EXPIRY)) AWS_EXPIRY, AWS_EXPIRY))
} }
# See: https://docs.djangoproject.com/en/dev/ref/settings/#static-url # URL that handles the media served from MEDIA_ROOT, used for managing stored files.
STATIC_URL = 'https://s3.amazonaws.com/%s/' % AWS_STORAGE_BUCKET_NAME 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 # EMAIL
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------

View File

@ -15,6 +15,11 @@ framework.
""" """
import os 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 # 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 # 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 # mod_wsgi daemon mode with each site in its own daemon process, or use
@ -24,9 +29,14 @@ os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.production")
# This application object is used by any WSGI server configured to use this # This application object is used by any WSGI server configured to use this
# file. This includes Django's development server, if the WSGI_APPLICATION # file. This includes Django's development server, if the WSGI_APPLICATION
# setting points here. # setting points here.
from django.core.wsgi import get_wsgi_application # noqa
application = get_wsgi_application() 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. # Apply WSGI middleware here.
# from helloworld.wsgi import HelloWorldApplication # from helloworld.wsgi import HelloWorldApplication
# application = HelloWorldApplication(application) # application = HelloWorldApplication(application)

View File

@ -2,8 +2,17 @@
# production that isn't in development. # production that isn't in development.
-r base.txt -r base.txt
gunicorn==19.3.0 # WSGI Handler
django-storages-redux==1.2.3 # ------------------------------------------------
Collectfast==0.2.3
gevent==1.0.1 gevent==1.0.1
gunicorn==19.3.0
# Static and Media Storage
# ------------------------------------------------
boto==2.38.0 boto==2.38.0
django-storages-redux==1.2.3
{% if cookiecutter.use_whitenoise == 'y' -%}
whitenoise==1.0.6
{% else %}
Collectfast==0.2.3
{%- endif %}