django 中 slice 和 truncatewords 不同用法???

django中取一段字符串中的前 N 个字符,可以用 slice和truncatewords ,但是两者是有区别的。

django的 模板过滤器 truncatewords ,取这个模板变量的前 N 个字符,只能用于英文
               模板过滤器slice, 取变量前 N 个字符,可用于中文 

如:

{{ content |truncatewords:"30" }}     变量前30个字符,用于中文不行
{{ content |slice:"30" }}        取变量前500个字符,可用于中文
原文地址:https://www.cnblogs.com/lmh001/p/9670099.html