11👍
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
0👍
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
Source:stackexchange.com