Django unittest self.assertTemplateUsed,如何检查多个模板的出现

Django unittest self.assertTemplateUsed, how to check the occurrence of multiple templates

self.assertTemplateUsed(response,('goods/item_list.html', 'base.html', 'inc/_nav.html') ,)

错误

AssertionError: False is not true : Template '('goods/item_list.html', 'base.html', 'inc/_nav.html')' was not a template used to render the response. Actual template(s) used: goods/items_list.html, base.html, inc/_nav.html

如何在响应中检查多个模板

您可以使用三种方法调用:

self.assertTemplateUsed(response, 'goods/items_list.html')
self.assertTemplateUsed(response, 'base.html')
self.assertTemplateUsed(response, 'inc/_nav.html')

或者您可以使用可迭代对象,并枚举该可迭代对象:

for <strong>template in</strong> ('goods/items_list.html', 'base.html', 'inc/_nav.html'):
    self.assertTemplateUsed(response, <strong>template</strong>)