Question

I have setup an AWS S3 bucket in order to transfer my static files in a remote CDN using the application django-storages, everything worked fine until I tried to compress my static files before uploading to S3 using django_compressor.

I have setup all the variables according django_compressor documentation for django-storages (https://django_compressor.readthedocs.org/en/latest/remote-storages/index.html)

I uploaded all the files in S3 using 'manage.py collectstatic' then:

When I do 'manage.py compress' I get this error:

CommandError: An error occured during rendering ../templates/base.html: 'https://my_bucket.s3.amazonaws.com/css/bootstrap.2.3.1.css' isn't accessible via COMPRESS_URL ('https://my_bucket.s3-external-3.amazonaws.com/') and can't be compressed

What's wrong with my setup?

Here is my settings.py configuration for django-storages and django_compressor:

COMPRESS_URL = 'https://mybucket_name.s3-external-3.amazonaws.com/'
STATIC_URL = COMPRESS_URL
DEFAULT_FILE_STORAGE = 'my_project.boto_custom.CachedS3BotoStorage'

AWS_ACCESS_KEY_ID = 'XXX'
AWS_SECRET_ACCESS_KEY = 'XXX'
AWS_STORAGE_BUCKET_NAME = 'mybucket_name'

COMPRESS_ROOT = STATIC_ROOT

COMPRESS_STORAGE = 'my_project.boto_custom.CachedS3BotoStorage'
STATICFILES_STORAGE = 'my_project.boto_custom.CachedS3BotoStorage'

COMPRESS_OFFLINE = True

Thanks for your help

Was it helpful?

Solution

I fixed it by adding one variable and it worked:

AWS_S3_CUSTOM_DOMAIN = 'my_bucket.s3-external-3.amazonaws.com'

OTHER TIPS

If you have separate S3 buckets for static and media you can also put it in your subclass of S3BotoStorage like so:

class CachedS3BotoStorage(S3BotoStorage):
  custom_domain = 'my_bucket.s3-external-3.amazonaws.com'

(or better yet set it to settings.AWS_S3_CUSTOM_STATIC_DOMAIN or something)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top