获取错误:Django.core.exceptions.impropertlyconfigured:在djang中,密钥设置不能为空

2024-05-13 05:11:30 发布

您现在位置:Python中文网/ 问答频道 /正文

当我尝试运行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'但我仍然收到错误,是否有人可以帮助我解决此问题

设置.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

Tags: pathdjangokeypyimportsecretsettingsos
1条回答
网友
1楼 · 发布于 2024-05-13 05:11:30

只要删除setting.py文件上的django.setup()就可以了

为了更清楚地说明这一点,当调用django.setup()时,它应该已经有一个设置文件,因此有一个SECRET_KEY;因此,它提出了这样一个错误

相关问题 更多 >