用于截断文本的Django模板标签 [英] Django template tag to truncate text

查看:113
本文介绍了用于截断文本的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 }}

请参阅这里的doc

这篇关于用于截断文本的Django模板标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆