我试图通过使用命令连接到数据库
from django.db import connection
来自python shell,但这产生了以下导入错误
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/django/db/__init__.py", line 11, in <module>
if DEFAULT_DB_ALIAS not in settings.DATABASES:
File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py", line 184, in inner
self._setup()
File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 40, in _setup
raise ImportError("Settings cannot be imported, because environment variable %s is undefined." % ENVIRONMENT_VARIABLE)
ImportError: Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined.
我使用 Django 1.4 和 PostgreSQL,当我使用早期版本的 django Plz 帮助时,成功执行了相同的命令。