この件に関する記事は既にいくつかありますが、私はdjango-compressor
を動作させるためにすべての組み合わせを試しましたが、成功しませんでした。何か案は?Heroku&Amazon S3のDjango-compressorエラー "UncompressableFileError"
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_URL
s3utils.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 name
index.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 ' isn't accessible via COMPRESS_URL (' https://mysite.s3.amazonaws.com/static/ ') and can't be compressed
だから私は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/
で、それ以外の場合は機能します。
セットアップ:
- Djangoのv1.10.6
- のPython V3.5
- ジャンゴ・コンプレッサー2.1.1