MCPcopy
hub / github.com/django/django / truncatechars

Function truncatechars

django/template/defaultfilters.py:307–313  ·  view source on GitHub ↗

Truncate a string after `arg` number of characters.

(value, arg)

Source from the content-addressed store, hash-verified

305@register.filter(is_safe=True)
306@stringfilter
307def truncatechars(value, arg):
308 """Truncate a string after `arg` number of characters."""
309 try:
310 length = int(arg)
311 except ValueError: # Invalid literal for int().
312 return value # Fail silently.
313 return Truncator(value).chars(length)
314
315
316@register.filter(is_safe=True)

Callers

nothing calls this directly

Calls 2

TruncatorClass · 0.90
charsMethod · 0.80

Tested by

no test coverage detected