Django assertTemplateUsed在redi之后失败

2021-01-28 07:31:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在做一个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')


^{pr2}$


settings.py
LOGOUT_REDIRECT_URL = '/accounts/login/'