Django tutorial 2.7.4 Test a view: setup_test_environment()

3310 단어 Other
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 "", 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 을 사용해야 합니다. 파이톤을 직접 시작할 수 없습니다. 앞의 2.4.4에서 언급한 바와 같이 이 명령은 자동으로 환경을 설정합니다.
  • Don’t use setup_test_environment in the shell in testing tutorial
  • Django Tutorial Error: Setting up the test client
  • 좋은 웹페이지 즐겨찾기