mirror of
https://github.com/cookiecutter/cookiecutter-django.git
synced 2025-07-13 09:32:26 +03:00
make it possible to serve up static assets using dj-static instead of S3
This commit is contained in:
parent
337269648d
commit
a6eefe40b9
|
@ -1 +1 @@
|
||||||
web: python {{cookiecutter.repo_name}}/manage.py run_gunicorn --settings=config.settings -b "0.0.0.0:$PORT" -w 3
|
web: gunicorn {{cookiecutter.repo_name}}/config/wsgi.py
|
|
@ -5,4 +5,5 @@
|
||||||
gunicorn==0.17.4
|
gunicorn==0.17.4
|
||||||
django-storages==1.1.4
|
django-storages==1.1.4
|
||||||
gevent==0.13.8
|
gevent==0.13.8
|
||||||
boto==2.9.5
|
boto==2.9.5
|
||||||
|
dj-static==0.0.5
|
|
@ -326,32 +326,42 @@ class Production(Common):
|
||||||
|
|
||||||
INSTALLED_APPS += ("gunicorn", )
|
INSTALLED_APPS += ("gunicorn", )
|
||||||
|
|
||||||
########## STORAGE CONFIGURATION
|
try: # serve static assets using S3
|
||||||
# See: http://django-storages.readthedocs.org/en/latest/index.html
|
########## STORAGE CONFIGURATION
|
||||||
INSTALLED_APPS += (
|
# See: http://django-storages.readthedocs.org/en/latest/index.html
|
||||||
'storages',
|
INSTALLED_APPS += (
|
||||||
)
|
'storages',
|
||||||
|
)
|
||||||
|
|
||||||
# See: http://django-storages.readthedocs.org/en/latest/backends/amazon-S3.html#settings
|
# See: http://django-storages.readthedocs.org/en/latest/backends/amazon-S3.html#settings
|
||||||
STATICFILES_STORAGE = DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
|
STATICFILES_STORAGE = DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
|
||||||
|
|
||||||
# See: http://django-storages.readthedocs.org/en/latest/backends/amazon-S3.html#settings
|
# See: http://django-storages.readthedocs.org/en/latest/backends/amazon-S3.html#settings
|
||||||
AWS_ACCESS_KEY_ID = values.SecretValue()
|
AWS_ACCESS_KEY_ID = values.SecretValue()
|
||||||
AWS_SECRET_ACCESS_KEY = values.SecretValue()
|
AWS_SECRET_ACCESS_KEY = values.SecretValue()
|
||||||
AWS_STORAGE_BUCKET_NAME = values.SecretValue()
|
AWS_STORAGE_BUCKET_NAME = values.SecretValue()
|
||||||
AWS_AUTO_CREATE_BUCKET = True
|
AWS_AUTO_CREATE_BUCKET = True
|
||||||
AWS_QUERYSTRING_AUTH = False
|
AWS_QUERYSTRING_AUTH = False
|
||||||
|
|
||||||
# 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_EXPIREY = 60 * 60 * 24 * 7
|
AWS_EXPIREY = 60 * 60 * 24 * 7
|
||||||
AWS_HEADERS = {
|
AWS_HEADERS = {
|
||||||
'Cache-Control': 'max-age=%d, s-maxage=%d, must-revalidate' % (AWS_EXPIREY,
|
'Cache-Control': 'max-age=%d, s-maxage=%d, must-revalidate' % (AWS_EXPIREY,
|
||||||
AWS_EXPIREY)
|
AWS_EXPIREY)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# See: https://docs.djangoproject.com/en/dev/ref/settings/#static-url
|
||||||
|
STATIC_URL = 'https://s3.amazonaws.com/%s/' % AWS_STORAGE_BUCKET_NAME
|
||||||
|
########## END STORAGE CONFIGURATION
|
||||||
|
except: # serve static assets using wsgi
|
||||||
|
PROJECT_PATH = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
STATIC_ROOT = 'staticfiles'
|
||||||
|
STATIC_URL = '/static/'
|
||||||
|
|
||||||
|
STATICFILES_DIRS = (
|
||||||
|
join(PROJECT_PATH, 'static'),
|
||||||
|
)
|
||||||
|
|
||||||
# See: https://docs.djangoproject.com/en/dev/ref/settings/#static-url
|
|
||||||
STATIC_URL = 'https://s3.amazonaws.com/%s/' % AWS_STORAGE_BUCKET_NAME
|
|
||||||
########## END STORAGE CONFIGURATION
|
|
||||||
|
|
||||||
########## EMAIL
|
########## EMAIL
|
||||||
DEFAULT_FROM_EMAIL = values.Value(
|
DEFAULT_FROM_EMAIL = values.Value(
|
||||||
|
|
|
@ -26,7 +26,9 @@ os.environ.setdefault("DJANGO_CONFIGURATION", "Local")
|
||||||
# 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 configurations.wsgi import get_wsgi_application
|
from configurations.wsgi import get_wsgi_application
|
||||||
application = get_wsgi_application()
|
from dj_static import Cling
|
||||||
|
|
||||||
|
application = Cling(get_wsgi_application())
|
||||||
|
|
||||||
# Apply WSGI middleware here.
|
# Apply WSGI middleware here.
|
||||||
# from helloworld.wsgi import HelloWorldApplication
|
# from helloworld.wsgi import HelloWorldApplication
|
||||||
|
|
Loading…
Reference in New Issue
Block a user