Last active
August 29, 2015 14:06
-
-
Save psychok7/2016cffe6322801ca876 to your computer and use it in GitHub Desktop.
Django Amazon S3 Settings
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DEFAULT_FILE_STORAGE = 'app.s3utils.MediaRootS3BotoStorage' | |
STATICFILES_STORAGE = 'app.s3utils.StaticRootS3BotoStorage' | |
AWS_ACCESS_KEY_ID = 'XXXXXXXXXXX' | |
AWS_SECRET_ACCESS_KEY = 'YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY' | |
AWS_STORAGE_BUCKET_NAME = 'app-bucket' | |
AWS_S3_SECURE_URLS = False # use http instead of https | |
AWS_QUERYSTRING_AUTH = False # we dont have any private files | |
S3_URL = 'http://s3-eu-west-1.amazonaws.com/%s' % AWS_STORAGE_BUCKET_NAME | |
MEDIA_ROOT = '/media/' | |
STATIC_ROOT = '/static/' | |
STATIC_URL = S3_URL + STATIC_ROOT | |
MEDIA_URL = S3_URL + MEDIA_ROOT | |
# create a file called s3utils.py in you project root (next to you settings.py) and add: | |
from storages.backends.s3boto import S3BotoStorage | |
# Using like this because of http://stackoverflow.com/a/18046120/977622 | |
class StaticRootS3BotoStorage(S3BotoStorage): | |
location = 'static' | |
class MediaRootS3BotoStorage(S3BotoStorage): | |
location = 'media' | |
# StaticRootS3BotoStorage = lambda: S3BotoStorage(location='static') | |
# MediaRootS3BotoStorage = lambda: S3BotoStorage(location='media') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment