回到顶部

阅读目录

django 模板中使用 widthratio 标签实现 乘法、除法 运算

先看官方文档

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 标签计算给定值与最大值的比率,然后将该比率应用于常量。

例子:

<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 }}

^_^
请喝咖啡 ×

文章部分资料可能来源于网络,如有侵权请告知删除。谢谢!

前一篇: Django simpleUI 修改 element-UI 引用的 index.js 和 index.css 链接 以及 base.html 的 vue 资源链接
下一篇: centos7 mysqlclient ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
captcha