在学习 《The difinitive guide to Django 2nd》models这章的时候,为mysite创建了一个app books,books中models已经创建了对应数据库的model,这个时候想用python shell环境来测试,但是输入
File "<stdin>", line 1, in <module>
File "books\models.py", line 1, in <module>
from django.db import models
File "C:\Python25\Lib\site-packages\django\db\__init__.py", line 11, in <modul
e>
if DEFAULT_DB_ALIAS not in settings.DATABASES:
File "C:\Python25\Lib\site-packages\django\utils\functional.py", line 184, in
inner
self._setup()
File "C:\Python25\Lib\site-packages\django\conf\__init__.py", line 40, in _set
up
raise ImportError("Settings cannot be imported, because environment variable
%s is undefined." % ENVIRONMENT_VARIABLE)
ImportError: Settings cannot be imported, because environment variable DJANGO_SE
TTINGS_MODULE is undefined.”
最重要的是最后一句,because environment variable DJANGO_SE
TTINGS_MODULE is undefined.
DJANGO_SE
TTINGS_MODULE 并未定义。
解决方法:在mysite目录下,用python manage.py shell启动python解释器环境,然后在from.. import ...成功。
from books.models import Publisher
的时候,报如下错误“Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "books\models.py", line 1, in <module>
from django.db import models
File "C:\Python25\Lib\site-packages\django\db\__init__.py", line 11, in <modul
e>
if DEFAULT_DB_ALIAS not in settings.DATABASES:
File "C:\Python25\Lib\site-packages\django\utils\functional.py", line 184, in
inner
self._setup()
File "C:\Python25\Lib\site-packages\django\conf\__init__.py", line 40, in _set
up
raise ImportError("Settings cannot be imported, because environment variable
%s is undefined." % ENVIRONMENT_VARIABLE)
ImportError: Settings cannot be imported, because environment variable DJANGO_SE
TTINGS_MODULE is undefined.”
最重要的是最后一句,because environment variable DJANGO_SE
TTINGS_MODULE is undefined.
DJANGO_SE
TTINGS_MODULE 并未定义。
解决方法:在mysite目录下,用python manage.py shell启动python解释器环境,然后在from.. import ...成功。