Django's Amazon S3 Configuration
This file contains 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
# | |
# 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,) |
This file contains 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
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