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. Inline truncate by character number by esanchez 3 years, 10 months ago
  2. JSON-compatible query filter specification by mhalle 4 years, 1 month ago
  3. Generate QR Code image for a string by johnnoone 3 years ago
  4. Slice filter by sneeu 5 years, 2 months ago
  5. Google Geocode Lookup by tonyskyday 4 years, 11 months ago

Comments

(Forgotten your password?)