Truncate Characters Filter (simple)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
from django import template

register = template.Library()

@register.filter
# truncate after a certain number of characters
def truncchar(value, arg):
    if len(value) < arg:
        return value
    else:
        return value[:arg] + '...'

More like this

  1. truncate letters by trbs 5 years, 2 months ago
  2. truncatestring filter by pigletto 3 years, 2 months ago
  3. Truncate filter by zalun 3 years ago
  4. Inline truncate by character number by esanchez 3 years, 10 months ago
  5. Truncate text to length up until the nearest space by phektus 1 year, 2 months ago

Comments

(Forgotten your password?)