Py学习  »  Django

用Intcomma格式化Django中的数字

massideux • 4 年前 • 1102 次点击  

我在尝试使用| intcomma格式化数字时遇到问题。

假设我将值a和b相乘,通过使用:

<h2>{% widthratio item.a 1 item.b %}</h2>

所有的例子都使用只有一个值的intcomma:

<h2>{{ item.a|intcomma }}</h2>

以下示例不起作用:

<h2>{% widthratio value|intcomma 1 value|intcomma %}
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/53128
 
1102 次点击  
文章 [ 1 ]  |  最新文章 4 年前
Iain Shelvington
Reply   •   1 楼
Iain Shelvington    4 年前

widthratio 接受论据 as <variable> ,它将计算结果存储在变量中,然后可以在模板中使用该变量

{% widthratio item.a 1 item.b as foo %}
<h2>{{ foo|intcomma }}</h2>