I created my own template filter, which adds a "..." to the end (last word) of the line (truncated):
from django import template register = template.Library() @register.filter("truncate_chars") def truncate_chars(value, max_length): if len(value) > max_length: truncd_val = value[:max_length] if not len(value) == max_length+1 and value[max_length+1] != " ": truncd_val = truncd_val[:truncd_val.rfind(" ")] return truncd_val + "..." return value
jki Aug 11 2018-11-11T00: 00Z
source share