title: Using Cloudfront with Django S3Boto
body: <p>I have successfully set up my app to use S3 for storing all static and media files. However, I would like to upload to S3 (current operation), but serve from a cloudfront instance I have set up. I have tried adjusting settings to the cloudfront url but it does not work. How can I upload to S3 and serve from Cloudfront please?</p>
  
  <p><strong>Settings</strong></p>
  
  <pre><code>AWS_S3_CUSTOM_DOMAIN = '%s.s3.amazonaws.com' % AWS_STORAGE_BUCKET_NAME
  
  DEFAULT_FILE_STORAGE = 'app.custom_storages.MediaStorage'
  STATICFILES_STORAGE = 'app.custom_storages.StaticStorage'
  
  STATICFILES_LOCATION = 'static'
  MEDIAFILES_LOCATION = 'media'
  
  STATIC_URL = "https://s3-eu-west-1.amazonaws.com/app/%s/" % (STATICFILES_LOCATION)
  MEDIA_URL = "https://%s/%s/" % (AWS_S3_CUSTOM_DOMAIN, MEDIAFILES_LOCATION)
  </code></pre>
  
  <p><strong>custom_storages.py</strong></p>
  
  <pre><code>from django.conf import settings
  from storages.backends.s3boto import S3BotoStorage
  
  class StaticStorage(S3BotoStorage):
      location = settings.STATICFILES_LOCATION
  
  class MediaStorage(S3BotoStorage):
      location = settings.MEDIAFILES_LOCATION
  </code></pre>