Skip to content

Instantly share code, notes, and snippets.

@bmispelon
Created January 28, 2013 16:02
Show Gist options
  • Select an option

  • Save bmispelon/4656729 to your computer and use it in GitHub Desktop.

Select an option

Save bmispelon/4656729 to your computer and use it in GitHub Desktop.
import re
from django import template
register = template.Library()
UNICODE_ESCAPE_SEQ = re.compile(r'\\x([0-9a-f]{2})
@register.filter
def htmlrepr(element):
return UNICODE_ESCAPE_SEQ.sub(r'&#x\1', repr(element))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment