【发布时间】:2020-04-07 11:25:55
【问题描述】:
我尝试浏览的每个页面都出现 500 个错误。我唯一要更改的是 DEBUG 为 False。
这是我的配置:
SECRET_KEY = os.environ.get("SECRET_KEY", "0$ke!x1bz5cj0mpzo1zfx4omw-c9iqw%m95zb)(2@ddg5s+3!f")
ALLOWED_HOSTS = ['*']
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False
# Application definition
INSTALLED_APPS = [
'posts', # Contains all dynamic and static pages related to posts
'courses', # Contains all dynamic and static pages related to courses and modules
'pages', # Contains all static pages that are not post related
'markdownx', # Allows for editing and creating markdown content
'jet.dashboard',
'jet', # Django admin theme override
'pwa', # Sets app to be PWA compliant
'whitenoise.runserver_nostatic', # Serving static files
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
从字面上看,我看到的每个答案都说只需将您的 ALLOWED_HOSTS 设置为 ['*'],正如您所见,我已经做到了,但仍然没有骰子。我检查了文档,他们对 DEBUG 模式的其他影响非常少见,文档的一部分说:
作为一项安全措施,Django 不会包含可能敏感的设置,例如 SECRET_KEY。具体来说,它将排除名称中包含以下任何内容的任何设置: 'API' '钥匙' '经过' '秘密' '签名' “代币”
https://docs.djangoproject.com/en/2.2/ref/settings/#debug
我唯一能想到的是 secret_key 没有被拾取,但如果是这样,你如何在生产中做到这一点?
编辑:有些人一直要求我将调试模式设置为 true 以获取回溯。问题是,当我将其设置为 true 时,我没有收到 500 错误,只有当 DEBUG = False 时才出现。
【问题讨论】:
-
500 错误应该在控制台/日志中创建回溯。
-
请贴日志以便了解实际问题。
-
使用
debug=True并查看错误消息。如果不清楚,请在此处发布。 -
问题是当 debug 为 True 时我没有得到错误,而 Debug False 设置回溯实际上就是:
python System check identified no issues (0 silenced). December 14, 2019 - 21:46:09 Django version 2.2.7, using settings 'canadiancoding.settings' Starting development server at http://127.0.0.1:8000/ Quit the server with CTRL-BREAK. [14/Dec/2019 21:46:14] "GET / HTTP/1.1" 500 27 -
@KieranWood 在 GitHub 上创建一个 repro 项目。
标签: python django python-3.x