我正在做一个django2.1实践项目。我测试的最后一行总是不及格。
如果发生重定向,assertTemplateUsed检查是否确实不起作用?
Traceback (most recent call last):
File "test_views.py", line 24, in test_home_page_not_login_redirect self.assertTemplateUsed(resp, 'users/home.html')
File "testcases.py", line 554, in assertTemplateUsed self.fail(msg_prefix + "No templates used to render the response")
AssertionError: No templates used to render the response
test_views.py
def test_home_page_not_login_redirect(self):
resp = self.client.get('/')
self.assertEqual(resp.status_code, 302)
self.assertRedirects(resp, '/accounts/login/?next=/')
self.assertTemplateUsed(resp, 'users/login.html')
settings.py
LOGOUT_REDIRECT_URL = '/accounts/login/'
目前没有回答
相关问题
PyPI热门下载资源包