Skip to content

Instantly share code, notes, and snippets.

@ekinertac
Last active April 11, 2018 03:47
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Django's Amazon S3 Configuration
#
# Install django-storages app with pip
# $ pip install django-storages
#
INSTALLED_APPS = (
...
'storages',
...
)
AWS_STORAGE_BUCKET_NAME = '**bucket-name**'
AWS_S3_REGION_NAME = 'eu-central-1' # e.g. us-east-2
AWS_ACCESS_KEY_ID="****"
AWS_SECRET_ACCESS_KEY="******"
AWS_S3_CUSTOM_DOMAIN = '%s.s3.amazonaws.com' % AWS_STORAGE_BUCKET_NAME
MEDIAFILES_LOCATION = 'media'
STATICFILES_LOCATION = 'static'
STATICFILES_STORAGE = 'config.utils.StaticStorage'
DEFAULT_FILE_STORAGE = 'config.utils.MediaStorage'
MEDIA_URL = '/%s/' MEDIAFILES_LOCATION
STATIC_ROOT = '/%s/' STATICFILES_LOCATION
STATIC_URL = 'http://%s/%s/' % (AWS_STORAGE_BUCKET_NAME, STATICFILES_LOCATION)
STATICFILES_DIRS = (STATICFILES_LOCATION,)
from django.conf import settings
from storages.backends.s3boto3 import S3Boto3Storage
class StaticStorage(S3Boto3Storage):
location = settings.STATICFILES_LOCATION
class MediaStorage(S3Boto3Storage):
location = settings.MEDIAFILES_LOCATION
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment