简体   繁体   中英

Django error 500 when Debug=False - allowed hosts set to *. nothing in console

when im setting Django to Debug=False, I am getting an error 500 when running via gunicorn or via manage.py. when running via manage I do not get any errors in console.

my settings file has the allowed hosts set to ['*']. As soon as I change Debug=True everything works again.

where would I get the output of the 500 if not from the console when running manage.py?

here is my settings file:

'''
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

When running a production server, according to the Django docs , you can get errors emailed to you, provided that you set the following in your settings.py (change the values with meaningful ones):

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'),
)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM