Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
检查django.test.TestCase中的模板名称_Django_Templates_Testing - Fatal编程技术网

检查django.test.TestCase中的模板名称

检查django.test.TestCase中的模板名称,django,templates,testing,Django,Templates,Testing,我正在尝试为我们的简单应用程序编写一个测试。尽管所有测试都在完美地运行,但我仍然希望检查视图渲染或重定向到的模板名称。检查视图渲染的模板的最佳方法是什么 可能是这样的: self.assertTrue('test.html' in self.templates) 或 如何实现这一点。来自: response=self.client.get(“/my/view/url”) 你能行 self.assertEqual(response.templates[0].name,“expected\u te

我正在尝试为我们的简单应用程序编写一个测试。尽管所有测试都在完美地运行,但我仍然希望检查视图渲染或重定向到的模板名称。检查视图渲染的模板的最佳方法是什么

可能是这样的:

self.assertTrue('test.html' in self.templates)

如何实现这一点。

来自:
response=self.client.get(“/my/view/url”)

你能行

self.assertEqual(response.templates[0].name,“expected\u template.html”)

或:

self.assertEqual(response.template[0].name,“预期的\u template.html”)

因为“模板”和“模板”是相同的数组。此数组列表的后续(非零)项包括或扩展了模板。

来源:
response=self.client.get(“/my/view/url”)

你能行

self.assertEqual(response.templates[0].name,“expected\u template.html”)

或:

self.assertEqual(response.template[0].name,“预期的\u template.html”)


因为“模板”和“模板”是相同的数组。此数组列表的后续(非零)项包括或扩展模板。

您应该使用
assertTemplateUsed
():


您应该使用
assertTemplateUsed
():

self.assertTrue(self.template.name, 'test.html')
response = self.client.get('/url/')
self.assertTemplateUsed(response, 'test.html')