当Debug = False时,Django错误500 - 允许主机设置为*。在控制台没什么

时间:2018-04-09 11:48:26

标签: python django

当我将Django设置为Debug = False时,我通过gunicorn或manage.py运行时收到错误500。当通过manage运行时,我在控制台中没有任何错误。

我的设置文件将允许的主机设置为['*']。一旦我改变Debug = True,一切都会再次起作用。

运行manage.py时,如果不是从控制台获取500的输出,我将在哪里获取?

这是我的设置文件:

'''
Django settings for itapp project.

For more information on this file, see
https://docs.djangoproject.com/en/dev/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/dev/ref/settings/
'''

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
import ldap

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

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/dev/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

ALLOWED_HOSTS = ['*']

# Application definition

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.humanize',
    'home.apps.HomeConfig',
    'oncall.apps.OncallConfig',
    'tools.apps.ToolsConfig',
    'sites.apps.SitesConfig',
    'maintenance.apps.MaintenanceConfig',
    'service.apps.ServiceConfig',
    'monitoring.apps.MonitoringConfig',
    'mgmt.apps.MgmtConfig',
    'config.apps.ConfigConfig',
    'circuits.apps.CircuitsConfig',
    'storages',
    'imagekit',
    'django_celery_results',
    'debug_toolbar',
    'simple_history',
    'crispy_forms',
)

MIDDLEWARE = [
    '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', 
    'debug_toolbar.middleware.DebugToolbarMiddleware',
    'simple_history.middleware.HistoryRequestMiddleware', 
]

ROOT_URLCONF = 'itapp.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [
            BASE_DIR + '/templates/',
            ],
        'APP_DIRS': True,
        'OPTIONS': {
            'debug' : DEBUG,
            'context_processors': [
                'django.template.context_processors.debug',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
                'django.template.context_processors.media',
                'django.template.context_processors.static',
                'itapp.context_processors.SiteLinks',
                'itapp.context_processors.QuickJumpLinks',
            ],
        },
    },
]
CRISPY_TEMPLATE_PACK = 'bootstrap3'
WSGI_APPLICATION = 'itapp.wsgi.application'

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

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'OPTIONS': {
            'init_command': "SET sql_mode='STRICT_TRANS_TABLES'",
        },
        'NAME': 'it_app_db_v2',
        'USER': '*****',
        'PASSWORD': '*****',
        'HOST': '****',
        'PORT': '3306',
    }
}

# Password validation
# https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators

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',
    },
]

INTERNAL_IPS = ('127.0.0.1',)

def show_toolbar(request):
    return True

DEBUG_TOOLBAR_CONFIG = {
    "SHOW_TOOLBAR_CALLBACK" : show_toolbar,
}

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

LANGUAGE_CODE = 'en-gb'

TIME_ZONE = 'Europe/London'

USE_I18N = True

USE_L10N = True

USE_TZ = False

1 个答案:

答案 0 :(得分:2)

运行生产服务器时,根据Django docs,您可以通过电子邮件向我发送错误,前提是您在settings.py中设置了以下内容(使用有意义的值更改值):

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'my.mail.server'
EMAIL_HOST_USER = ''
EMAIL_HOST_PASSWORD = ''
EMAIL_PORT = 25
EMAIL_USE_SSL = False
DEFAULT_FROM_EMAIL = 'mydjango@example.com'
SERVER_EMAIL = 'mydjango@example.com'

ADMINS = (
    ('Your name Here', 'your.email@example.com'),
)

MANAGERS = (
    ('Your name Here', 'your.email@example.com'),
)
相关问题