Menu Close

How to perform HTML decoding/encoding using Python Django?

To perform HTML decoding/encoding using Python Django, we can use escape and unescape.

For instance, we write

from html import escape

print(escape("<"))

to escape the '<' string.

And we reverse the escaping with

from html import unescape  

print(unescape("&gt;"))

to call unescape to unescape the "&gt;" string.

Posted in Python, Python Answers