【发布时间】:2022-03-27 01:25:21
【问题描述】:
当我在数字海洋上运行服务器并在我的 django 应用程序的 Settings.py 中设置 DEBUG = False 时,我收到 500 错误。我在端口 8000 上运行 Django 服务器,并且在使用 gunicorn 时遇到了同样的问题。 DEBUG = True 和我的 ALLOWED_HOSTS = ['*'] 时没有出现错误。我有一个自定义的 404 模板和处理程序。该错误出现在我尝试加载的任何页面上,除了 Django 管理页面。如果您有任何想法,请告诉我!!!
确切的错误消息:"GET /accounts/login/ HTTP/1.1" 500 27
settings.py文件:
import os
from pathlib import Path
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
SECRET_KEY = '**********'
MAILMAN_PASSWORD = "*********"
DEBUG = False
ALLOWED_HOSTS = ['*']
INSTALLED_APPS = [
'mysite',
'webapp',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles'
]
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',
]
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',
],
},
},
]
WSGI_APPLICATION = 'mysite.wsgi.application'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'dashboard_db',
'USER': 'dashboard_db_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',
},
]
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
STATIC_URL = '/static/'
LOGIN_REDIRECT_URL = '/'
LOGOUT_REDIRECT_URL = '/'
STATIC_ROOT = os.path.join(BASE_DIR,'static/')
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'webapp', 'static'),
]
【问题讨论】:
-
你有应用程序的日志吗?
-
GET /accounts/login/ HTTP/1.1 500 27不是错误消息。在网络服务器错误日志中查找真正的错误消息。 -
检查 nginx 或 apche 日志
-
您说
DEBUG = True时也没有显示错误,但是.. 网站运行良好吗?还是与DEBUG = False时的行为相同? -
我现在遇到了这个问题.. 在数字海洋上
标签: python django deployment digital-ocean internal-server-error