Skip to content

Instantly share code, notes, and snippets.

@ekinertac
Last active April 11, 2018 03:47
Show Gist options
  • Save ekinertac/53f75d6ad39bf6771a456a8585dbff24 to your computer and use it in GitHub Desktop.
Save ekinertac/53f75d6ad39bf6771a456a8585dbff24 to your computer and use it in GitHub Desktop.
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