I suggest you use the truncatewords template template.
Template example:
<ul> {% for blogpost in blogposts %} <li><b>{{blogpost.title}}</b>: {{blogpost.content|truncatewords:10}}</li> {% endfor %} </ul>
If your blog content is stored as HTML, use truncatewords_html to ensure that open tags close after the truncation point (or combine with striptags to remove html tags).
If you want to trim characters (not words), you can use slice :
{{blogpost.content|slice:":10"}}
(displays the first 10 characters).
If the content is stored as HTML, combine with striptags to avoid problems with open tags: {{blogpost.content|striptags|slice:":10"}}
codeape
source share