# the function def divisibleby(value, arg): "Returns true if the value is devisible by the argument" return int(value) % int(arg) == 0 # template {% for athlete in athletes_team.list %} {% if forloop.counter|divisibleby:"3" %}{% endif %} {% if footloop.counter|add:"2"|divisibleby:"3" %}{% endif %} {% endfor %}