DEBUG = False在Django中返回服务器错误(500)

时间:2019-03-21 11:54:01

标签: python django

当我将Django应用程序中的变量DEBUG更改为False时,即使我将允许的主机更改为['*'],我仍然收到服务器错误(500)。

这是我的settings.py文件:

import os
import django_heroku


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


SECRET_KEY = '************'

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


ALLOWED_HOSTS = ['*']

# Application definition

INSTALLED_APPS = [
    'Clientes.apps.ClientesConfig',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'multiselectfield',
    'crispy_forms',
    'djrill',
    'redactor',
    'django_cron',
    'rest_framework',
    'rest_framework.authtoken',
    'import_export',
]


CRON_CLASSES = [
    'Clientes.cron.MyCronJob',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': (
        'rest_framework.authentication.TokenAuthentication',
    ),
    'DEFAULT_PERMISSION_CLASSES': (
        'rest_framework.permissions.IsAdminUser',
    ),
}


TEMPLATE_CONTEXT_PROCESSORS = (
    'django_admin_dialog.context_processors.django_admin_dialog',
)

ROOT_URLCONF = 'Checkstore.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',
            ],
        },
    },
]

WSGI_APPLICATION = 'Checkstore.wsgi.application'

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

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}

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

# Password validation
# https://docs.djangoproject.com/en/2.0/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',
    },
]


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

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True

DATE_INPUT_FORMATS = ['%d/%m/%Y']

CRISPY_TEMPLATE_PACK = 'bootstrap3'
COMPRESS_ENABLED = os.environ.get('COMPRESS_ENABLED', False)

# STATICFILES_STORAGE = 'Clientes.storage.WhiteNoiseStaticFilesStorage'
STATIC_URL = 'Clientes/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')

# Extra places for collectstatic to find static files.
STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'Clientes/static'),
)
django_heroku.settings(locals())

MEDIA_URL = '/media/'

MEDIA_ROOT = os.path.join(BASE_DIR, 'Clientes/media')


LOGIN_REDIRECT_URL = 'client:profile'

我还试图将localhost添加到允许的主机和IP地址中。

该项目被推送到Heroku,每次尝试将其推送到Heroku时,都会遇到相同的错误。

任何人都可以澄清这段代码有什么问题吗?

编辑

这是我设置DEBUG = True时的部署结果:

Counting objects: 8, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (8/8), done.
Writing objects: 100% (8/8), 1.00 KiB | 1.00 MiB/s, done.
Total 8 (delta 6), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote: 
remote: -----> Locale app detected
remote: === Updating or installing language-pack-pt-base
remote: Hit:1 http://archive.ubuntu.com/ubuntu bionic InRelease
remote: Get:2 http://archive.ubuntu.com/ubuntu bionic-security InRelease [88.7 kB]
remote: Hit:3 http://apt.postgresql.org/pub/repos/apt bionic-pgdg InRelease
remote: Hit:4 http://archive.ubuntu.com/ubuntu bionic-updates InRelease
remote: Fetched 88.7 kB in 1s (149 kB/s)
remote: Reading package lists...
remote: Reading package lists...
remote: Building dependency tree...
remote: The following additional packages will be installed:
remote:   language-pack-pt
remote: The following NEW packages will be installed:
remote:   language-pack-pt language-pack-pt-base
remote: 0 upgraded, 2 newly installed, 0 to remove and 31 not upgraded.
remote: Need to get 0 B/2,621 kB of archives.
remote: After this operation, 12.7 MB of additional disk space will be used.
remote: Download complete and in download only mode
remote: === Unpacking and configuring all locales
remote: -----> Python app detected
remote:        Skipping installation, as Pipfile.lock hasn't changed since last deploy.
remote: -----> Discovering process types
remote:        Procfile declares types -> release, web
remote: 
remote: -----> Compressing...
remote:        Done: 290.4M
remote: -----> Launching...
remote:  !     Release command declared: this new release will not be available until the command succeeds.
remote:        Released v99
remote:        https://scalestore-app.herokuapp.com/ deployed to Heroku
remote: 
remote: Verifying deploy... done.
remote: Running release command...
remote: 
remote: /app/.heroku/python/lib/python3.6/site-packages/psycopg2/__init__.py:144: UserWarning: The psycopg2 wheel package will be renamed from release 2.8; in order to keep installing from binary please use "pip install psycopg2-binary" instead. For details see: <http://initd.org/psycopg/docs/install.html#binary-install-from-pypi>.
remote:   """)
remote: Operations to perform:
remote:   Apply all migrations: Clientes, admin, auth, authtoken, contenttypes, django_cron, sessions
remote: Running migrations:
remote:   No migrations to apply.
remote: Waiting for release.... done.
To https://git.heroku.com/scalestore-app.git
   297e2ee9..f56f4aae  master -> master

0 个答案:

没有答案
相关问题