gpt4 book ai didi

python - 在 Django 中运行 Managepy Shell 时的设置问题

转载 作者:太空宇宙 更新时间:2023-11-03 18:47:29 25 4
gpt4 key购买 nike

我有一个在虚拟环境中运行的 django 实例

# python manage.py shell
Traceback (most recent call last):
File "manage.py", line 3, in <module>
from app.models import *
File "/production/project/app/models.py", line 1, in <module>
from django.db import models
File "/production/pythonenv/django15/lib/python2.7/site-packages/django/db/__init__.py", line 11, in <module>
if settings.DATABASES and DEFAULT_DB_ALIAS not in settings.DATABASES:
File "/production/pythonenv/django15/lib/python2.7/site-packages/django/conf/__init__.py", line 53, in __getattr__
self._setup(name)
File "/production/pythonenv/django15/lib/python2.7/site-packages/django/conf/__init__.py", line 46, in _setup
% (desc, ENVIRONMENT_VARIABLE))
django.core.exceptions.ImproperlyConfigured: Requested setting DATABASES, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

解决这个问题最简单的方法是什么?

最佳答案

在你的manage.py文件中..放置以下行-:

import os

os.environ["DJANGO_SETTINGS_MODULE"] = "settings" # "settings" will be your django settings file path

关于python - 在 Django 中运行 Managepy Shell 时的设置问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19179339/

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