因此,我知道已经有一些关于这个主题的文章,但我尝试了每一个组合的设置,使django-compressor工作,但没有成功。有什么想法吗?
settings.py
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
# other finders..
'compressor.finders.CompressorFinder',
)
STATICFILES_DIRS = (
os.path.join(BASE_DIR, "static"),
)
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles/')
STATIC_URL = '/static/'
DEFAULT_FILE_STORAGE = "mysite.s3utils.MediaS3BotoStorage"
COMPRESS_ROOT = STATIC_ROOT
STATICFILES_STORAGE = 'mysite.storage.CachedS3BotoStorage'
COMPRESS_STORAGE = STATICFILES_STORAGE
COMPRESS_URL = STATIC_URLs3utils.py
from django.core.files.storage import get_storage_class
from storages.backends.s3boto import S3BotoStorage
class StaticS3BotoStorage(S3BotoStorage):
"""
Storage for static files.
"""
def __init__(self, *args, **kwargs):
kwargs['location'] = 'static'
super().__init__(*args, **kwargs)
class MediaS3BotoStorage(S3BotoStorage):
"""
Storage for uploaded media files.
"""
def __init__(self, *args, **kwargs):
kwargs['location'] = 'media'
super().__init__(*args, **kwargs)
class CachedS3BotoStorage(S3BotoStorage):
"""
S3 storage backend that saves the files locally, too.
"""
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.local_storage = get_storage_class(
"compressor.storage.CompressorFileStorage")()
def save(self, name, content):
self.local_storage._save(name, content)
super().save(name, self.local_storage._open(name))
return nameindex.html
{% load compress %}
{% compress css %}
<link href="{% static 'libs/twitter-bootstrap/css/bootstrap.min.css' %}" rel="stylesheet">
{% endcompress %}错误:
compressor.exceptions.UncompressableFileError:'https://mysite.s3.amazonaws.com:443/libs/twitter-bootstrap/css/bootstrap.min.css‘无法通过COMPRESS_URL ('https://mysite.s3.amazonaws.com/static/')访问,无法压缩
因此,我从跟踪错误中了解到,由于django-compressor使用了以下代码,所以会引发此错误:
if not url.startswith(base_url):
raise UncompressableFileError(
"'%s' isn't accesible via COMPRESS_URL ('%s') and can't be"
" compressed" % (url, base_url))因此,似乎由于某种原因,COMPRESS_URL正在使用:443端口,并且缺少/static/后缀,否则它将工作。
设置:
https://stackoverflow.com/questions/42680704
复制相似问题