Задать вопрос

Тел: +7 965 3737 888

406

Просмотров

1

Ответов

Word-boundary-aware string truncation template filter

<p>This is a custom template filter that allows you to truncate a string to a maximum of num characters, but respecting word boundaries. So, for example, if string = "This is a test string.", then {{ string|truncatechars:12 }} would give you "This is a..." instead of "This is a te".</p>

Вопрос полезен? Да0/Нет0
file_2351.py(1.3Кб)
None

Ответы (1):

Ответandrewingram:22.05.2009
Ответ полезен? Да0/Нет0

Truncate words will give you 'n' words regardless of length. Often when you want to truncate you will be working with a character limit rather than a word limit.

Truncating just characters is ugly because you end up with partial words - what this filter does is truncate characters but ensure you only get whole words.