静态文件保存在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
<myproject>.storage.CachedS3BotoStorage
关于压缩器为何不压缩的任何想法?
编辑:此实现与Django调试工具栏混在一起,因此似乎在静态文件路径“有效”中使用'https://s3.amazonaws.com/<my_prod-bucket>/static/'
,但与此同时设置又使调试工具栏变糟。