【问题标题】:I got error when I turn DEBUG true on settings file在设置文件上将 DEBUG 设置为 true 时出现错误
【发布时间】:2021-04-24 03:50:53
【问题描述】:

当我在 settings.py 上打开 DEBUG True 时出现 Error500,但当 DEBUG 为 False 时一切正常。 python manage.py collectstatic 也可以。 这是我的settings.py。我会感谢你的帮助。我使用的是 Django 2.2 版本。

Django 设置

"""
Django settings for samamarche project.

Generated by 'django-admin startproject' using Django 2.2.

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

For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.2/ref/settings/
"""
import dj_database_url
import os
import django_heroku
if os.environ.get('ENV') == 'PRODUCTION':
    # ...
    db_from_env = dj_database_url.config(conn_max_age=500)
    #DATABASES['default'] = dj_database_url.config(conn_max_age=600, ssl_require=True)
    DATABASES['default'].update(db_from_env)

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

SECRET_KEY = os.environ.get('SECRET_KEY', 'xxxxxxxxxxxxxxx')
DEBUG = True
# 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',
    'phonenumber_field',
    'marche',
    'cart',
    'commandes',
    'payment',
    'coupons',
    #'accounts',
    'crispy_forms',
    'users',
]
MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'whitenoise.middleware.WhiteNoiseMiddleware',
    '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'
]

【问题讨论】:

标签: python django


【解决方案1】:

我认为添加ALLOWED_HOSTS = ['*'] 可以解决问题

【讨论】:

  • 已经完成。我不能把所有的设置都放在那里。我正在努力。
猜你喜欢
  • 2015-08-25
  • 1970-01-01
  • 2019-07-04
  • 1970-01-01
  • 1970-01-01
  • 2017-01-02
  • 1970-01-01
  • 1970-01-01
  • 2011-11-18
相关资源
最近更新 更多