Skip to content

Instantly share code, notes, and snippets.

@qoelet
Created June 4, 2010 07:35
Show Gist options
  • Save qoelet/425105 to your computer and use it in GitHub Desktop.
Save qoelet/425105 to your computer and use it in GitHub Desktop.
def escape(html):
"""
Returns the given HTML with ampersands, quotes and angle brackets encoded.
"""
return mark_safe(force_unicode(html).replace('&', '&amp;').replace('<', '&lt;').replace('>', '&gt;').replace('"', '&quot;').replace("'", '&#39;'))
escape = allow_lazy(escape, unicode)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment