我正在从这里做Django入门教程: https://docs.djangoproject.com/en/1.9/intro/tutorial05/
如上所述,我打开了python shell并尝试导入项目,如下所示:
from polls.models import Question
然而,我收到此错误:
django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
我不太了解错误信息。我应该在何处定义DJANGO_SETTINGS_MODULE
或致电settings.configure()
?
如果我尝试打开django shell,我会得到相同的消息。
答案 0 :(得分:6)
从项目的根目录运行python manage.py shell
- 它会自动设置指向项目设置的环境变量。
或者,事先通过django-admin
设置环境变量来打开Django shell:
$ export DJANGO_SETTINGS_MODULE="myproj.settings"
$ django-admin shell # requires the DJANGO_SETTINGS_MODULE to be set
另见: