我已经设置了一个AWS S3存储桶,以便使用应用程序django-storages在远程CDN中传输我的静态文件, 一切正常,直到我尝试压缩我的静态文件,然后使用django_compressor上传到S3。
我根据django-storages(https://django_compressor.readthedocs.org/en/latest/remote-storages/index.html)的django_compressor文档设置了所有变量
我使用'manage.py collectstatic'上传了S3中的所有文件,然后:
当我执行'manage.py compress'时出现此错误:
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
我的设置有什么问题?
以下是django-storages和django_compressor的settings.py配置:
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
感谢您的帮助
答案 0 :(得分:6)
我通过添加一个变量来修复它,它起作用了:
AWS_S3_CUSTOM_DOMAIN = 'my_bucket.s3-external-3.amazonaws.com'
答案 1 :(得分:1)
如果您有静态和媒体的单独S3存储桶,您也可以将它放在S3BotoStorage的子类中,如下所示:
class CachedS3BotoStorage(S3BotoStorage):
custom_domain = 'my_bucket.s3-external-3.amazonaws.com'
(或者更好的是将其设置为settings.AWS_S3_CUSTOM_STATIC_DOMAIN
或其他)