How can I use greater than or equal to operator for forloop counter in django template? I want to do something like:
{% if forloop.counter<=12 or forloop.counter>=25 %}
But it is giving me an error:
Could not parse the remainder: '<=12' from 'forloop.counter<=12'
A for loop is used for iterating over a sequence, like looping over items in an array, a list, or a dictionary.
{% endblock %} </div> </body> </html> In this example, the {% block %} tags define four blocks that child templates can fill in. All the block tag does is tell the template engine that a child template may override those portions of the template.
Ans: We can use the range function but there is no range tag or function in Django template.
counter indicates how many times the for tag has gone through its loop.
Try this by keeping space around operator
{% if forloop.counter <= 12 or forloop.counter >= 25 %}
https://docs.djangoproject.com/es/1.10/ref/templates/builtins/#id4, i think the problem is that you forgot the space betwen the operator and the variable. foorloop.counter <= 12
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With