先看官方文档
http://doc.codingdict.com/django/ref/templates/builtins.html#std:templatetag-widthratio(中文)
https://docs.djangoproject.com/zh-hans/2.2/ref/templates/builtins/#std:templatetag-widthratio(英文)
For creating bar charts and such, this tag calculates the ratio of a given value to a maximum value, and then applies that ratio to a constant.
为了创建条形图等,widthratio 标签计算给定值与最大值的比率,然后将该比率应用于常量。
例子:
代码语言:javascript复制<img src="bar.png" alt="Bar"
height="10" width="{% widthratio this_value max_value max_width %}">
If this_value
is 175, max_value
is 200, and max_width
is 100, the image in the above example will be 88 pixels wide (because 175/200 = .875; .875 * 100 = 87.5 which is rounded up to 88).
如果 this_value 是175,max_value 是 200,并且 max_width 是 100,则上述示例中的图像将是88像素宽(因为 175 / 200 = .875; .875 * 100 = 87.5,上舍入为 88)。
widthratio 乘法
也就是把第二个参数改成数字:1
{% widthratio this_value 1 max_width %}
widthratio 除法
也就是把最后一个参数改成数字:1
{% widthratio this_value max_value 1 %}
模板减法
{{ value | add:-10 }}