Skip to content

Instantly share code, notes, and snippets.

@bjinwright
Created December 7, 2016 22:50
Show Gist options
  • Save bjinwright/b51e1c09711238d81c009e9d6732b7e3 to your computer and use it in GitHub Desktop.
Save bjinwright/b51e1c09711238d81c009e9d6732b7e3 to your computer and use it in GitHub Desktop.
Custon S3 Django-Storages backend made for use with CloudFront with multiple origins
from django.conf import settings
from django.utils.encoding import filepath_to_uri
from storages.backends.s3boto import S3BotoStorage
class StaticStorage(S3BotoStorage):
location = settings.STATICFILES_LOCATION
def url(self, name, headers=None, response_headers=None, expire=None):
return '{}{}'.format(settings.STATIC_URL,filepath_to_uri(name))
class MediaStorage(S3BotoStorage):
location = settings.MEDIAFILES_LOCATION
def url(self, name, headers=None, response_headers=None, expire=None):
return '{}{}'.format(settings.MEDIA_URL, filepath_to_uri(name))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment