我正在尝试在 jinja2 中制作一个 mod,但没有办法。
{% 设置索引 = 1 %}
选项1:
{% for .... %}
{% if {{index % 3 == 0}} %}
{% endif %}
{% set index = index + 1 %}
{% endfor %}
选项2:
{% for .... %}
{% if index.index is divisibleby 3 %}
{% endif %}
{% set index = index + 1 %}
{% endfor %}
有什么想法吗?
谢谢
最佳答案
您只需要从第一个 if 语句中删除 {{ }}。此代码有效...
<!-- {% set index = 9 %} -->
{% set index = 10 %}
{% if index % 3 == 0 %}hi
{% endif %}
{% set index = index + 1 %}
希望这有帮助!
关于jinja2 - 如何计算jinja2中整数除法的余数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23994021/