我有一个观点:
type
我正在使用class DashboardView(TemplateView):
template_name = "dashboard/dashboard.html"
进行测试:
TestCase
此测试失败,并显示class TestAuthorisedViews(TestCase):
@classmethod
def setUpTestData(cls):
cls.url = reverse('dashboard')
cls.client = Client()
cls.response = cls.client.get(cls.url)
def test_view_uses_correct_template(self):
print('template', self.response.__dict__)
self.assertTemplateUsed(self.response, 'dashboard/dashboard.html')
。
但是,我包含在测试中的AssertionError: No templates used to render the response
调试显示了确实使用模板的响应:
print()
我正确使用此测试吗?在查看the source code时,错误似乎失败了,因为template {'template_name': ['dashboard/dashboard.html'], 'context_data': {
'view': <dashboard.views.DashboardView object at 0x0000019E9CF33040> }, // etc >}
而不是response.templates = []
。