Django test client response context None

南楼画角 提交于 2019-12-03 23:21:40
Joe J

You need to add the test setup statement.

import django
django.test.utils.setup_test_environment() 

Find more details by following my link: http://jazstudios.blogspot.com/2011/01/django-testing-views.html

From Django documentation:

Although * your code * [+] would work in the Python interactive interpreter, some of the test client's functionality, notably the template-related functionality, is only available while tests are running. The reason for this is that Django's test runner performs a bit of black magic in order to determine which template was loaded by a given view. This black magic (essentially a patching of Django's template system in memory) only happens during test running.

So if you run it in a test run, it should work.

You can see this question

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!