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