How can i round a value in django template without using the filter

五迷三道 提交于 2019-12-18 07:36:13

问题


Is there any way that I can do some python math function in django template. Actually I need to round a variable value and I want to achieve this without using the filters.

For example like {{math.round(total)}}.


回答1:


You can use floatformat to round of the value in django template.

{{ total|floatformat }}

If you want to perform more mathematical operations, you can try django-mathfilters. Or you could write your custom template tag and perform the operations in that template tag.



来源:https://stackoverflow.com/questions/18185351/how-can-i-round-a-value-in-django-template-without-using-the-filter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!