【问题标题】:Django unittest self.assertTemplateUsed, how to check the occurrence of multiple templatesDjango unittest self.assertTemplateUsed,如何检查多个模板的出现
【发布时间】:2021-10-08 16:37:31
【问题描述】:
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')' 不是用于呈现 回复。实际使用的模板:goods/items_list.html、base.html、 inc/_nav.html

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

【问题讨论】:

    标签: python django django-unittest


    【解决方案1】:

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

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-27
      • 2012-04-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-19
      • 2019-09-06
      相关资源
      最近更新 更多