gpt4 book ai didi

python - django.core.exceptions.ImproperlyConfigured : Requested setting LOGGING_CONFIG

转载 作者:行者123 更新时间:2023-12-01 06:26:01 24 4
gpt4 key购买 nike

我收到以下回溯,它似乎与 Django 3.0.2 中所做的更改有关?如果有人能解释我在这里做错了什么,我将不胜感激。

(myDjangoEnv) D:\Django\django_lectures\first_project>python populate_first_app.py
Traceback (most recent call last):
File "populate_first_app.py", line 5, in <module>
django.setup()
File "C:\Users\ABC\.conda\envs\myDjangoEnv\lib\site-packages\django\__init__.py", line 19, in setup
configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
File "C:\Users\ABC\.conda\envs\myDjangoEnv\lib\site-packages\django\conf\__init__.py", line 76, in __getattr__
self._setup(name)
File "C:\Users\ABC\.conda\envs\myDjangoEnv\lib\site-packages\django\conf\__init__.py", line 57, in _setup
raise ImproperlyConfigured(
django.core.exceptions.ImproperlyConfigured: Requested setting LOGGING_CONFIG, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

这是我的代码:

import  os
os.environ.setdefault('DJANGO_SETTING_MODULE', 'first_project.settings')

import django
django.setup()

##FAKER POP SCRIPT
import random
from first_app.models import AccessRecord, Topic, Webpage
from faker import Faker

fakegen = Faker()
topics = ['Search', 'Social', 'Marketplace', 'News', 'Game']

def add_topic():
t = Topic.objects.get_or_create(top_name = random.choice(topics))[0]
t.save()
return t


def populate(N = 5):

for entry in range(N):

#get the topic for the entry
top = add_topic()

#Create fake data for that entry
fake_url = fakegen.url()
fake_date = fakegen.date()
fake_name = fakegen.company()

#Create new webpage entry
webpage = Webpage.objects.get_or_create(topic = top, url= fake_url, name = fake_name)[0]

#Create a fake AccessRecord for that webpage
acc_rec = AccessRecord.objects.get_or_create(name = webpage, date = fake_date)[0]


if __name__ == '__main__':
print("populate Script!")
populate(20)
print("populating Complete!")

最佳答案

您需要设置环境变量DJANGO_SETTINGS_MODULE,而不是DJANGO_SETTING_MODULE。请注意 SETTINGS 末尾的 S

尝试编辑第二行来阅读

os.environ['DJANGO_SETTINGS_MODULE'] = 'first_project.settings'

关于python - django.core.exceptions.ImproperlyConfigured : Requested setting LOGGING_CONFIG,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60139740/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com