用于截断文本的Django模板标签
问题描述:
Django具有截断词模板标记,可以剪切给定字数的文字。但是没有像 truncatechars 。在给定的字符长度限制下,剪切模板中最好的方法是什么?
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?
答
最近在Django 1.4中添加了。例如:
This has recently been added in Django 1.4. e.g.:
{{ value|truncatechars:9 }}