Django tutorial 2.7.4 Test a view
from django.test.utils import setup_test_environment
setup_test_environment()
输出:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/mohitgupta/.virtualenvs/Django/lib/python2.7/site-packages/django/test/utils.py", line 104, in setup_test_environment
mail._original_email_backend = settings.EMAIL_BACKEND
File "/Users/mohitgupta/.virtualenvs/Django/lib/python2.7/site-packages/django/conf/__init__.py", line 46, in __getattr__
self._setup(name)
File "/Users/mohitgupta/.virtualenvs/Django/lib/python2.7/site-packages/django/conf/__init__.py", line 40, in _setup
% (desc, ENVIRONMENT_VARIABLE))
django.core.exceptions.ImproperlyConfigured: Requested setting EMAIL_BACKEND, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
必须使用命令 python manage.py shell
调用shell,不能直接启动Python,这在前面的章节2.4.4中已提到,此命令将会自动设置环境。