社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Django

用Intcomma格式化Django中的数字

massideux • 6 年前 • 2477 次点击  

我在尝试使用| 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
文章 [ 1 ]  |  最新文章 6 年前
Iain Shelvington
Reply   •   1 楼
Iain Shelvington    6 年前

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

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