django 模板中无法实现计算,收集的方案。
摘要: 用django的divisibleby标签实现,如下:代码片段, 请查看文章详情 ...
用django的divisibleby标签实现,如下:
{% 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 }}