Django-compressor和S3 Boto:静态文件未压缩

时间:2018-10-01 20:27:11

标签: django amazon-s3 boto3 django-compressor

错误

静态文件保存在S3中-但是未压缩。

我的代码

HTML

Ipython

生产设置

{% compress css %}
<link href="{{ STATIC_URL }}css/project.css" rel="stylesheet" type="text/css" charset="utf-8">
{% endcompress %}

CachedS3BotoStorage

COMPRESS_ENABLED = True
STATICFILES_STORAGE = '<myproject>.storage.CachedS3Boto3Storage'
COMPRESS_STORAGE = STATICFILES_STORAGE
COMPRESS_URL = STATIC_URL
COMPRESS_FILTERS = {
    'css': ['compressor.filters.css_default.CssAbsoluteFilter'],
    'js': ['compressor.filters.jsmin.JSMinFilter']
}

建议

docs显示的结果将是这样-

from django.core.files.storage import get_storage_class
from storages.backends.s3boto3 import S3Boto3Storage


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

    def save(self, name, content):
        self.local_storage._save(name, content)
        super(CachedS3Boto3Storage, self).save(name, self.local_storage._open(name))
        return name

我可以确认的内容

  • 我的STATIC_ROOT = '/path/to/staticfiles' COMPRESS_ROOT = STATIC_ROOT STATICFILES_STORAGE = 'mysite.storage.CachedS3BotoStorage' COMPRESS_STORAGE = STATICFILES_STORAGE STATIC_URL = 'https://compressor-test.s3.amazonaws.com/' COMPRESS_URL = STATIC_URL COMPRESS_ROOT相同:STATIC_ROOT
  • '/app/staticfiles'指向STATICFILES_STORAGE
  • STATIC_URL为<myproject>.storage.CachedS3BotoStorage
  • COMPRESS_URL == STATIC_URL

想法?

关于压缩器为何不压缩的任何想法?

编辑:此实现与Django调试工具栏混在一起,因此似乎在静态文件路径“有效”中使用'https://s3.amazonaws.com/<my_prod-bucket>/static/',但与此同时设置又使调试工具栏变糟。

0 个答案:

没有答案