Math comparison operating in Django .96 templates

若如初见. 提交于 2019-12-13 02:14:15

问题


i want to compare do simple math in django template

like {% forloop.counter > 5 %} {% endfor %}

how do i achieve this?


回答1:


This isn't really possible, because Django deliberately provides a very limited syntax, which doesn't include math operators. You could do this by writing a custom template filter, but it's a poor idea - you'd be better off preprocessing the data before passing it in so you don't require the math operator. That's certainly what Django wants you to do, anyway.



来源:https://stackoverflow.com/questions/3151237/math-comparison-operating-in-django-96-templates

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