2016-11-27 6 views
1

問題の問題を特定するのに問題があります。Django-Compressorはamazonawsとherokuを使用してdjango-storageでUncompressableFileErrorをスローします

設定フォルダがあり、その中にlocal.py、common.py、production.pyがあります。すべてがうまくいっていて、ローカルホストでは圧縮されていますが、英雄では圧縮されていません。

私はそれを展開するとき、私はエラーを取得しています:

Internal Server Error:/

UncompressableFileError at/
'https://xxxxx.s3.amazonaws.com/static/css/stylesheet.css' isn't accessible via COMPRESS_URL ('//xxxxx.s3.amazonaws.com/static/') and can't be compressed 

common.py

# STATIC FILE CONFIGURATION 
# ------------------------------------------------------------------------------ 
# See: https://docs.djangoproject.com/en/dev/ref/settings/#static-root 
STATIC_ROOT = str(ROOT_DIR('staticfiles')) 

# See: https://docs.djangoproject.com/en/dev/ref/settings/#static-url 
STATIC_URL = '/static/' 

# See: https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#std:setting-STATICFILES_DIRS 
STATICFILES_DIRS = (
    str(APPS_DIR.path('static')), 
) 

# See: https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#staticfiles-finders 
STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder', 
    'django.contrib.staticfiles.finders.AppDirectoriesFinder', 
    'compressor.finders.CompressorFinder', 
) 

# MEDIA CONFIGURATION 
# ------------------------------------------------------------------------------ 
# See: https://docs.djangoproject.com/en/dev/ref/settings/#media-root 
MEDIA_ROOT = str(APPS_DIR('media')) 

# See: https://docs.djangoproject.com/en/dev/ref/settings/#media-url 
MEDIA_URL = '/media/' 


COMPRESS_OFFLINE_CONTEXT = { 
    'STATIC_URL': STATIC_URL, 
    'MEDIA_URL': MEDIA_URL, 
} 

COMPRESS_ENABLED=True 

production.py

DEFAULT_FILE_STORAGE = 'config.custom_storages.MediaStorage' 
THUMBNAIL_DEFAULT_STORAGE = DEFAULT_FILE_STORAGE 


AWS_ACCESS_KEY_ID = env('DJANGO_AWS_ACCESS_KEY_ID') 
AWS_SECRET_ACCESS_KEY = env('DJANGO_AWS_SECRET_ACCESS_KEY') 
AWS_STORAGE_BUCKET_NAME = env('DJANGO_AWS_STORAGE_BUCKET_NAME') 
AWS_S3_CUSTOM_DOMAIN = '{}.s3.amazonaws.com'.format(AWS_STORAGE_BUCKET_NAME) 
AWS_AUTO_CREATE_BUCKET = True 
AWS_QUERYSTRING_AUTH = False 
AWS_S3_CALLING_FORMAT = OrdinaryCallingFormat() 


# AWS cache settings, don't change unless you know what you're doing: 
AWS_EXPIRY = 60 * 60 * 24 * 7 

# TODO See: https://github.com/jschneier/django-storages/issues/47 
# Revert the following and use str after the above-mentioned bug is fixed in 
# either django-storage-redux or boto 
AWS_HEADERS = { 
    'Cache-Control': six.b('max-age=%d, s-maxage=%d, must-revalidate' % (
     AWS_EXPIRY, AWS_EXPIRY)) 
} 

# URL that handles the media served from MEDIA_ROOT, used for managing 
# stored files. 
MEDIAFILES_LOCATION = 'media' 
MEDIA_URL = "//%s/%s/" % (AWS_S3_CUSTOM_DOMAIN, MEDIAFILES_LOCATION) 


# Static Assests 
# ------------------------ 
COMPRESS_ROOT = STATIC_ROOT 
STATICFILES_STORAGE = 'config.custom_storages.CachedS3BotoStaticStorage' 
COMPRESS_STORAGE = 'config.custom_storages.CachedS3BotoStaticStorage' 

AWS_S3_SECURE_URLS = True 

STATICFILES_LOCATION = 'static' 
STATIC_URL = "//%s/%s/" % (AWS_S3_CUSTOM_DOMAIN, STATICFILES_LOCATION) 


# See: https://github.com/antonagestam/collectfast 
# For Django 1.7+, 'collectfast' should come before 
# 'django.contrib.staticfiles' 
AWS_PRELOAD_METADATA = True 
INSTALLED_APPS = ['collectfast', ] + INSTALLED_APPS 

custom_storages.py

from django.conf import settings 
from storages.backends.s3boto import S3BotoStorage 
from django.core.files.storage import get_storage_class 


class StaticStorage(S3BotoStorage): 
    location = settings.STATICFILES_LOCATION 
    file_overwrite = True 


class MediaStorage(S3BotoStorage): 
    location = settings.MEDIAFILES_LOCATION 
    file_overwrite = False 


class CachedS3BotoStaticStorage(S3BotoStorage): 
    """ 
    S3 storage backend that saves the files locally, too. 
    """ 
    location = 'static' 

    def __init__(self, *args, **kwargs): 
     super(CachedS3BotoStaticStorage, self).__init__(*args, **kwargs) 
     self.local_storage = get_storage_class(
      "compressor.storage.CompressorFileStorage")() 

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

答えて

1

私はこの問題を解決しようとすると全体の夜を過ごしたと私は、このコードにはほとんど変化作っ:私はそれは、HTTPまたはHTTPSを追加することができます考えて、私はちょうどのためにそう

AWS_S3_SECURE_URLS = True 

を持って

isn't accessible via COMPRESS_URL ('//xxxxx.s3.amazonaws.com/static/') 

をテストでは、私はこの

のようにハードコードさ

https: 

を追加しました

それが動作し始めた、それは素晴らしいです。しかし、誰もそれを認識していない、またはhttpやhttpsを追加していない理由を説明することはできますか?

関連する問題