gpt4 book ai didi

django - 是否可以使用 django_compressor/S3/gzip?

转载 作者:行者123 更新时间:2023-12-04 03:28:50 27 4
gpt4 key购买 nike

如何使用 django_compressor 将 gzip 文件发送到 Amazon S3?

我尝试了多种方法,但没有奏效。这是我最后的 settings.py 配置:

COMPRESS_ENABLED = True
COMPRESS_OFFLINE = True

COMPRESS_ROOT = STATIC_ROOT
COMPRESS_URL = "http://xxx.cloudfront.net/"
STATIC_URL = COMPRESS_URL
COMPRESS_OUTPUT_DIR = 'CACHE'

#COMPRESS_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
COMPRESS_STORAGE = 'core.storage.CachedS3BotoStorage'

STATICFILES_STORAGE = 'compressor.storage.GzipCompressorFileStorage'
COMPRESS_YUI_BINARY = 'java -jar contrib/yuicompressor-2.4.7/build/yuicompressor-2.4.7.jar'
COMPRESS_YUI_JS_ARGUMENTS = ''
COMPRESS_CSS_FILTERS = ['compressor.filters.yui.YUICSSFilter']
COMPRESS_JS_FILTERS = ['compressor.filters.yui.YUIJSFilter']
COMPRESS_CSS_HASHING_METHOD = 'hash'

和我的 存储.py
from django.core.files.storage import get_storage_class
from storages.backends.s3boto import S3BotoStorage

class CachedS3BotoStorage(S3BotoStorage):
"""
S3 storage backend that saves the files locally, too.
"""
def __init__(self, *args, **kwargs):
super(CachedS3BotoStorage, self).__init__(*args, **kwargs)
self.local_storage = get_storage_class(
"compressor.storage.CompressorFileStorage")()

def save(self, name, content):
name = super(CachedS3BotoStorage, self).save(name, content)
self.local_storage._save(name, content)
return name

最佳答案

django-storages S3 存储后端 supports gzip .添加到settings.py:

AWS_IS_GZIPPED = True

关于django - 是否可以使用 django_compressor/S3/gzip?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15177801/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com