简体   繁体   English

一起使用django-storages和django-compressor时尝试压缩静态文件时出错

[英]Error when trying to compress static files when using django-storages and django-compressor together

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. 我已经设置了一个AWS S3存储桶,以便使用应用程序django-storage在远程CDN中传输我的静态文件,一切正常,直到我尝试压缩我的静态文件,然后使用django_compressor上传到S3。

I have setup all the variables according django_compressor documentation for django-storages ( https://django_compressor.readthedocs.org/en/latest/remote-storages/index.html ) 我已经根据django_compressor文档为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: 我使用“ manage.py collectstatic”上传了S3中的所有文件,然后:

When I do 'manage.py compress' I get this error: 当我'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

What's wrong with my setup? 我的设置有什么问题?

Here is my settings.py configuration for django-storages and django_compressor: 这是我的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

Thanks for your help 谢谢你的帮助

我通过添加一个变量对其进行了修复,并且可以正常工作:

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

If you have separate S3 buckets for static and media you can also put it in your subclass of S3BotoStorage like so: 如果您有用于静态和媒体的单独的S3存储桶,也可以将其放在S3BotoStorage的子类中,如下所示:

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) (或者更好的是将其settings.AWS_S3_CUSTOM_STATIC_DOMAINsettings.AWS_S3_CUSTOM_STATIC_DOMAIN或其他)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM