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

标签 python django amazon-s3 django-storage django-compressor

我已经设置了一个 AWS S3 存储桶,以便使用应用程序 django-storages 在远程 CDN 中传输静态文件, 一切工作正常,直到我尝试使用 django_compressor 上传到 S3 之前压缩静态文件。

我已经根据 django_compressor 文档为 django-storages 设置了所有变量( https://django_compressor.readthedocs.org/en/latest/remote-storages/index.html )

我使用“manage.pycollectstatic”上传了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

感谢您的帮助

最佳答案

我通过添加一个变量来修复它,它起作用了:

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

关于python - 一起使用 django-storages 和 django-compressor 时尝试压缩静态文件时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16623901/

相关文章:

python - 使用 FileHandler 的模式 ='w' 参数时,记录到 python 文件不会覆盖文件

python - 在没有 manage.py 的情况下从 Django 库运行单元测试

python - 在 Django 中从 facebook 的服务器端身份验证捕获 access_token

django - 为每个用户检索最相关输出的最佳解决方案(在 Django 或任何后端中)?

python - 如何取消进行中的 Requests.Session.Get 请求?

python - 根据域对大电子邮件文件进行排序显示错误

python-2.7 - 如何使用 boto3 get_object (Python 2.7) 从 S3 获取多个对象

python - botocore.exceptions.ConnectTimeoutError : Connect timeout on endpoint URL

actionscript-3 - 从 Flash 请求带有 + 号的 URL

python - Python 中二维列表中的字符串