django 使用templates模板过滤器限制字符数
如果需要阶段是字符串,则可以利用切片过滤器,它会将字符串视为字符列表。如果是一组单词,则粗略的等价词是truncatewords。
truncatewords
...
在截断结果的末尾还添加了省略号。
slice使用示例:
{{ variable|slice:":255" }}
truncatewords使用示例:
{{ variable|truncatechars:255 }}
参考:https://docs.djangoproject.com/en/dev/ref/templates/builtins/#truncatechars
还没有留言,还不快点抢沙发?