1

我有一个在虚拟环境中运行的 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.

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

4

2 回答 2

1

在您的 manage.py 文件中.. 放入以下行 - :

import os

os.environ["DJANGO_SETTINGS_MODULE"] = "settings"  # "settings" will be your django settings file path
于 2013-10-04T12:12:08.493 回答
0

export DJANGO_SETTINGS_MODULE=settings

于 2013-10-04T10:49:22.333 回答