gpt4 book ai didi

python - django.core.exceptions.ImproperlyConfigured : Requested setting LOGGING_CONFIG, 但未配置设置

转载 作者:太空狗 更新时间:2023-10-29 17:21:37 27 4
gpt4 key购买 nike

我正在尝试运行一个填充脚本,该脚本是我从 tango_with_django 教程 (https://github.com/leifos/tango_with_django/blob/master/tango_with_django_project/populate_rango.py) 中组合在一起的,但是我得到了以下回溯,它似乎与 Django 1.7 中所做的更改有关?如果有人能解释我在这里做错了什么,我将不胜感激。

(test_env) C:\Users\WriteCode\test_env\epl>python populate_clubs.py
Traceback (most recent call last):
File "populate_clubs.py", line 4, in <module>
django.setup()
File "c:\Python27\lib\site-packages\django\__init__.py", line 20, in setup
configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
File "c:\Python27\lib\site-packages\django\conf\__init__.py", line 46, in __ge
tattr__
self._setup(name)
File "c:\Python27\lib\site-packages\django\conf\__init__.py", line 40, in _set
up
% (desc, ENVIRONMENT_VARIABLE))
django.core.exceptions.ImproperlyConfigured: Requested setting LOGGING_CONFIG, b
ut settings are not configured. You must either define the environment variable
DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

(test_env) C:\Users\WriteCode\test_env\epl>

我的 populate_clubs.py 脚本

import os
import sys
import django
django.setup()


def add_club(name, nickname, manager, established, stadium, active=True):
c = clubs.objects.get_or_create(name=name, nickname=nickname, manager=manager, established=established, stadium=stadium, active=active)
return c

def populate():
add_club(name = "Aston Villa",
nickname = "Villans",
manager = "Tim Sherwood",
established = "1897",
stadium = "Villa Park"
)

# Print out what was added
for c in clubs.objects.all():
print "The following has been added to clubs:" + c



# Start execution
if __name__ == '__main__':
print "Starting club population script..."
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'epl.settings')
from teams.models import clubs
populate()

最佳答案

您可以在 django.setup() 行之前插入 os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")

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

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