truncatestring filter

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
from django.template import Library
register = Library()
from django.template.defaultfilters import stringfilter

@register.filter
@stringfilter
def truncatestring(src, ln):
    ret = src[:ln]
    if len(src)>ln:
        ret = ret[:ln-3]+'...'
    return ret

More like this

  1. Truncate Characters Filter (simple) by leahculver 6 years, 1 month ago
  2. Inline truncate by character number by esanchez 4 years, 10 months ago
  3. truncate letters by trbs 6 years, 2 months ago
  4. Truncate words by characters by trodrigues 5 years ago
  5. truncate by alfor 6 years, 1 month ago

Comments

(Forgotten your password?)