2017-04-22 8 views
0

EDIT:詳細:Djangoのlocalhostが500エラーサーバーエラーを与えたときにDEBUG = Falseの、しかしALLOWED_HOSTS = [ '*']

私は最初の回答で示唆されているようにログインを追加し、この得た:

ValueError: The file 'file/name' could not be found with <whitenoise.storage.CompressedManifestStaticFilesStorage object 

オリジナルPOST:

ローカルでDjangoサイトを実行していますが、DEBUG = Trueの場合はうまくいきます。しかし、DEBUG = Falseを設定すると、500 Server Errorが返されます。

ALLOWED_HOSTSが['*']に設定されており、それでも500のサーバーエラーが返されます。

import os 
import dj_database_url 

# Build paths inside the project like this: os.path.join(BASE_DIR, ...) 
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__)) 


# Quick-start development settings - unsuitable for production 
# See https://docs.djangoproject.com/en/1.10/howto/deployment/checklist/ 

# SECURITY WARNING: keep the secret key used in production secret! 
SECRET_KEY = "**************************" 

# SECURITY WARNING: don't run with debug turned on in production! 
DEBUG = False 

# Application definition 

INSTALLED_APPS = [ 
    'my_app.apps.MyAppConfig', 
    'django.contrib.admin', 
    'django.contrib.auth', 
    'django.contrib.contenttypes', 
    'django.contrib.sessions', 
    'django.contrib.messages', 
    # Disable Django's own staticfiles handling in favour of WhiteNoise, for 
    # greater consistency between gunicorn and `./manage.py runserver`. See: 
    # http://whitenoise.evans.io/en/stable/django.html#using-whitenoise-in-development 
    'whitenoise.runserver_nostatic', 
    'django.contrib.staticfiles', 
] 

MIDDLEWARE = [ 
    'django.middleware.security.SecurityMiddleware', 
    'whitenoise.middleware.WhiteNoiseMiddleware', 
    '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', 
] 

ROOT_URLCONF = 'mysite.urls' 

TEMPLATES = [ 
    { 
     'BACKEND': 'django.template.backends.django.DjangoTemplates', 
     'DIRS': [], 
     'APP_DIRS': True, 
     'OPTIONS': { 
      'context_processors': [ 
       'django.template.context_processors.debug', 
       'django.template.context_processors.request', 
       'django.contrib.auth.context_processors.auth', 
       'django.contrib.messages.context_processors.messages', 
      ], 
      'debug': DEBUG, 
     }, 
    }, 
] 

WSGI_APPLICATION = 'mysite.wsgi.application' 


# Database 
# https://docs.djangoproject.com/en/1.10/ref/settings/#databases 

DATABASES = { 
    'default': { 
     'ENGINE': 'django.db.backends.postgresql', 
     'NAME': 'my_db', 
     'USER': 'admin', 
     'PASSWORD': '', 
     'HOST': 'localhost', 
     'PORT': '', 
    } 
} 

AUTH_PASSWORD_VALIDATORS = [ 
    { 
     'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 
    }, 
    { 
     'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 
    }, 
    { 
     'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 
    }, 
    { 
     'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 
    }, 
] 

# Internationalization 
# https://docs.djangoproject.com/en/1.10/topics/i18n/ 

LANGUAGE_CODE = 'en-us' 
TIME_ZONE = 'America/Los_Angeles' 
USE_I18N = True 
USE_L10N = True 
USE_TZ = True 

# Update database configuration with $DATABASE_URL. 
db_from_env = dj_database_url.config(conn_max_age=500) 
DATABASES['default'].update(db_from_env) 

# Honor the 'X-Forwarded-Proto' header for request.is_secure() 
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') 

# Allow all host headers 
ALLOWED_HOSTS = ['*'] 

# Static files (CSS, JavaScript, Images) 
# https://docs.djangoproject.com/en/1.10/howto/static-files/ 

STATIC_ROOT = os.path.join(PROJECT_ROOT, 'staticfiles') 
STATIC_URL = '/static/' 

# Extra places for collectstatic to find static files. 
STATICFILES_DIRS = [ 
    os.path.join(PROJECT_ROOT, 'static'), 
] 

# Simplified static file serving. 
# https://warehouse.python.org/project/whitenoise/ 
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage' 
+1

サーバー上でどのようなエラーが出ていますか? – danielunderwood

+0

無効な 'ALLOWED_HOSTS'は、' 500サーバーエラー 'ではなく' 400 Bad Request'レスポンスをもたらします。別のエラーが発生した場合は、事前に詳細をお知らせいただく必要があります。 – knbk

+0

エラー:ValueError:[ハッシュ]の HLH

答えて

0

これにアプローチする正しい方法は、ログを有効にすることですとDjango自体は(通常は)問題を示します:

は、ここに私のsettings.pyです。このアプローチの利点は、将来の問題にも役立つことです。ここでDEBUG=falseでログインしますサンプルのロギングの設定が(this answerから借りた)です:

# settings.py 
LOGGING = { 
    'version': 1, 
    'disable_existing_loggers': False, 
    'formatters': { 
     'verbose': { 
      'format' : "[%(asctime)s] %(levelname)s [%(name)s:%(lineno)s] %(message)s", 
      'datefmt' : "%d/%b/%Y %H:%M:%S" 
     }, 
     'simple': { 
      'format': '%(levelname)s %(message)s' 
     }, 
    }, 
    'handlers': { 
     'file': { 
      'level': 'DEBUG', 
      'class': 'logging.FileHandler', 
      'filename': 'mysite.log', 
      'formatter': 'verbose' 
     }, 
    }, 
    'loggers': { 
     'django': { 
      'handlers':['file'], 
      'propagate': True, 
      'level':'DEBUG', 
     }, 
     'MYAPP': { 
      'handlers': ['file'], 
      'level': 'DEBUG', 
     }, 
    } 
} 
関連する問題