我想要类似于 string formatting from the standard library 的东西.
'%' Percentage. Multiplies the number by 100 and displays in fixed ('f') format, followed by a percent sign.
最佳答案
我正在寻找几乎相同的问题,并找到了 widthratio 模板标签。 您可以使用此标签根据计算百分比的原始值和总值计算模板中的百分比,而不是像在您的问题中那样计算百分比。如果您只需要一个没有精度的整数百分比,它就可以完成这项工作:
{% widthratio value total_value 100 %}
引用:https://docs.djangoproject.com/en/dev/ref/templates/builtins/#widthratio
关于django - 是否有 django 模板过滤器来显示百分比?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2751319/