2016-06-05 4 views
2

디버그가 해제 된 상태에서 heroku에서 내 django 앱을 실행할 때 500 오류가 발생했습니다.django/whitenoise 저장 장치 백엔드에서 오류가 발생합니다.

ValueError: The file 'media/img 1.jpg' could not be found with <whitenoise.storage.CompressedManifestStaticFilesStorage object at 0x7f795706f550>. 

내가 그것을 제거하고 기본 장고를 STATICFILES_STORAGE ='django.contrib.staticfiles.storage.StaticFilesStorage' 설정을 사용함으로써 STATICFILES_STORAGE 설정과 관련이있다 파악이 작동 : 아이디어를 얻을 롤 바를 사용 후 는 오류가 happaning 이유는은 다음보고 . 그러나이 세 가지 없음의 작동과 모두 같은 오류가 발생합니다 : whitenoise troubleshooting에서

STATICFILES_STORAGE ='django.contrib.staticfiles.storage.ManifestStaticFilesStorage' 
STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage' 
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage' 

가 장고의 manifestStaticFiles 스토리지를 사용하려고 말한다하고 문제가 다음 계속되면 문제는 장고에 있으며 백색 잡음 없습니다.

이 내 생산 설정은 다음과 같습니다

from django.conf import settings 

import os 

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware', 
    'django.middleware.common.CommonMiddleware', 
    'django.middleware.csrf.CsrfViewMiddleware', 
    'django.contrib.auth.middleware.AuthenticationMiddleware', 
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware', 
    'django.contrib.messages.middleware.MessageMiddleware', 
    'django.middleware.clickjacking.XFrameOptionsMiddleware', 
    'django.middleware.security.SecurityMiddleware', 
    'whitenoise.middleware.WhiteNoiseMiddleware', 
    'rollbar.contrib.django.middleware.RollbarNotifierMiddleware', 
) 


DEBUG = False 

# Email debugging configuration 

ADMINS = (
    ('david', '[email protected]'), 
) 

EMAIL_USE_TLS = True 

EMAIL_HOST = 'smtp.gmail.com' 

EMAIL_HOST_USER = '[email protected]' 

EMAIL_HOST_PASSWORD = '*******' 

EMAIL_PORT = 587 


# Honor the 'X-Forwarded-Proto' header for request.is_secure() 

SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') 

ALLOWED_HOSTS = ['evening-garden-60868.herokuapp.com'] 

ROLLBAR = { 
    'access_token': '*******************', 
    'environment': 'development' if DEBUG else 'production', 
    'branch': 'master', 
    'root': '/absolute/path/to/code/root', 
} 

STATICFILES_DIRS = (
    os.path.join(BASE_DIR,"studio", "static"), 
) 

STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles') 

STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage' 
+0

데이비드, 우리는 또한 같은 문제가 현재 수정을 찾기 위해 노력하고 있습니다. 하나를 찾으면 여기에 게시하십시오! – chris

+0

참조 http://stackoverflow.com/questions/35507140/django-staticfiles-not-found-on-heroku-with-whitenoise – Flimm

+0

[이 페이지의] (https : //devcenter.heroku. co.kr/articles/django-assets)? –

답변

1

나는이 같은 static 도우미 기능을 사용하여 미디어 파일을 제공하는 생각 : 당신 static 도우미 기능을 사용하기 때문에

urlpatterns = [ 
    ... 
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) 

미디어 파일을 제공하지 in project/urls.py는 DEBUG가 켜져있을 때만 작동합니다. 프로덕션 환경에서 사용자가 업로드 한 콘텐츠를이 방법으로 제공하는 경우 security concerns이 있습니다.

사용자의 콘텐츠가 안전하다고 확신하는 경우이 제한을 제거 할 수 있습니다.

def static(prefix, view=serve, **kwargs): 
    ... 
    # No-op if not in debug mode or an non-local prefix 
    if not settings.DEBUG or (prefix and '://' in prefix): 
     return [] 
    elif not prefix: 
     raise ImproperlyConfigured("Empty static prefix not permitted") 
    return [ 
     url(r'^%s(?P<path>.*)$' % re.escape(prefix.lstrip('/')), view, kwargs=kwargs), 
    ] 
관련 문제