当我尝试运行django
时,出现错误django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty
,settings.py文件SECRET_KEY = 'g1tmo148kxtw#^obw&apoms%n=&4g+2qi1ssuc$v3(fig-he4u'
中已经存在SECRET_KEY仍然出现错误,有人可以帮忙吗我该如何解决这个问题?
settings.py
import django
django.setup()
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'g1tmo148kxtw#^obw&apoms%n=&4g+2qi1ssuc$v3(fig-he4u'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
答案 0 :(得分:1)
只需删除django.setup()
文件上的setting.py
,一切就好了。
为进一步说明,在调用django.setup()
时,它应该已经有一个设置文件,因此应该有一个SECRET_KEY
;因此会引发这样的错误。