Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a Python equivalent to the PHP function htmlspecialchars()?

Is there a similar or equivalent function in Python to the PHP function htmlspecialchars()? The closest thing I've found so far is htmlentitydefs.entitydefs().

like image 410
Ian Avatar asked May 31 '09 05:05

Ian


2 Answers

Closest thing I know about is cgi.escape.

like image 76
Karl Guertin Avatar answered Sep 21 '22 17:09

Karl Guertin


from django.utils.html import escape
print escape('<div class="q">Q & A</div>')
like image 31
Agonych Avatar answered Sep 20 '22 17:09

Agonych