Last week I started a post series exploring the django.utils module. In this second part I will be focusing more
on the html module.
HTML
Module: django.utils.html
escape
Returns the given text with ampersands, quotes and angle brackets encoded for use in HTML.
It will cause already escaped strings to be escaped again:
If this is a concern, use conditional_escape() instead.
conditional_escape
format_html
This function is similar to str.format, but it will conditional escape all the arguments. Prefer to use it to build
small HTML fragments instead of str.format or string interpolation, as it is safer.
Safely format HTML fragments:
format_html_join
A wrapper of format_html, for the common case of a group of arguments that need to be formatted using the same format
string.