Django has truncatewords
template tag, which cuts the text at the given word count. But there is nothing like truncatechars.
What's the best way to cut the text in the template at given char-length limit?
text import Truncator >>> Truncator("Django template tag to truncate text") <Truncator: <function <lambda> at 0x10ff81b18>> >>>Truncator("Django template tag to truncate text"). words(3) u'Django template tag...' Truncator("Django template tag to truncate text").
Truncate statement in SQL is meant to empty a table for future use. Though Django doesn't provide a builtin to truncate a table, but still similar result can be achived using delete() method. For example: >>> Category. all().
lorem. Displays random “lorem ipsum” Latin text. This is useful for providing sample data in templates. A number (or variable) containing the number of paragraphs or words to generate (default is 1).
This has recently been added in Django 1.4. e.g.:
{{ value|truncatechars:9 }}
See doc here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With