如何在Django / Python模板中显示数字的圆形版本? [重复]

问题描述 投票:0回答:1

这个问题在这里已有答案:

我正在使用Django和Python 3.7。在我的模板中,我有这个

{{ round(articlestat.votes) }}

这会导致错误

Could not parse the remainder: '(articlestat.votes)' from 'round(articlestat.votes)'

有没有办法显示我的数字的圆形版本而不在模型中创建额外的@property方法?每次我希望数据格式有点不同时,做一个方法似乎有些过分。

python django python-3.x templates rounding
1个回答
0
投票

我建议你使用floatformat过滤器:

{{ articlestat.votes|floatformat:"0" }} 
© www.soinside.com 2019 - 2024. All rights reserved.