django template filter
上一节老王我说了下django template 语法,可以通过django来把view里的数据显示在页面里,这节主要说下django template filter.
django template 字符截取
slice
Returns a slice of the list.
Example:
{{ some_list|slice:":2" }}
If some_list is ['a', 'b', 'c'], the output will be ['a', 'b'].
django template 去掉html格式
striptags
Strips all [X]HTML tags.
For example:
{{ value|striptags }}
If value is "Joel is a slug", the output will be "Joel is a slug".
template 获取字符串长度
Returns the length of the value. This works for both strings and lists.
For example:
{{ value|length }}
If value is ['a', 'b', 'c', 'd'], the output will be 4.
如果要详细了解django template的格式语法的话。可以看下相关的文档