@register.filter(is_safe=True)
@stringfilter
def truncatechars_html(value, arg):
 try:
  length = int(arg)
 except ValueError:
  return value
 return Truncator(value).chars(length, html=True)

@ register . filter ( is_safe = True ) @ stringfilter def truncatechars_html ( value , arg ) : try : length = int ( arg ) except ValueError : return value return Truncator ( value ) . chars ( length , html = True )
truncates html after a certain number of chars .