Search code examples
htmldjango-templatesdjango-unittest

Django test can't find br tag


I use linebreaks in template. But the test can't find 'br' tag.

{{ book.short_description | linebreaks }}

This is the test

self.assertContains(response, "New<br></br>Lines")

Solution

  • You need to set html to True in order to handle text as HTML:

    self.assertContains(response, "New<br></br>Lines", html=True);
    

    Or you can use assertHTMLEqual. I hope this will help.