django 模板中无法实现计算,收集的方案。
By:Roy.LiuLast updated:2012-02-23
用django的divisibleby标签实现,如下:
divisibleby标签的意义是用后面的参数去除,除尽为True,否则为False
====================================================================
django模板内的字符串截取
参考http://docs.djangoproject.com/en/1.2/ref/templates/builtins/#built-in-filter-reference
{{ content |truncatewords:"30″ }} 变量前30个字符,用于中文不行
{{ content |slice:"30″ }} 取变量前500个字符,可用于中文
====================================================================
django模板内的简单计算
参考http://docs.djangoproject.com/en/1.2/ref/templates/builtins/#built-in-filter-reference
简单相加
{{ result.complete_quality|add:result.work_bearing|add:result.complete_speed }}
{% for each in somelist %} {% if forloop.counter0|divisibleby:2 %} {% else %} {% endif %} {% endfor %}
divisibleby标签的意义是用后面的参数去除,除尽为True,否则为False
====================================================================
django模板内的字符串截取
参考http://docs.djangoproject.com/en/1.2/ref/templates/builtins/#built-in-filter-reference
{{ content |truncatewords:"30″ }} 变量前30个字符,用于中文不行
{{ content |slice:"30″ }} 取变量前500个字符,可用于中文
====================================================================
django模板内的简单计算
参考http://docs.djangoproject.com/en/1.2/ref/templates/builtins/#built-in-filter-reference
简单相加
{{ result.complete_quality|add:result.work_bearing|add:result.complete_speed }}
From:一号门
Previous:ubuntu 常用命令,操作跟帖
Next:转载一个python基类,多态的文章
COMMENTS