test.SimpleTestCase.assertTemplateUsed()

SimpleTestCase.assertTemplateUsed(response, template_name, msg_prefix='', count=None) [source]

Asserts that the template with the given name was used in rendering the response.

The name is a string such as 'admin/index.html'.

The count argument is an integer indicating the number of times the template should be rendered. Default is None, meaning that the template should be rendered one or more times.

You can use this as a context manager, like this:

with self.assertTemplateUsed('index.html'):
    render_to_string('index.html')
with self.assertTemplateUsed(template_name='index.html'):
    render_to_string('index.html')
doc_Django
2016-10-09 18:40:06
Comments
Leave a Comment

Please login to continue.