Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Greater than or equal to forloop counter django template

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'

like image 586
Nikhil Sardana Avatar asked Oct 13 '16 16:10

Nikhil Sardana


People also ask

What is Forloop counter in Django?

A for loop is used for iterating over a sequence, like looping over items in an array, a list, or a dictionary.

What does {% endblock %} mean?

{% 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.

Can I use range in Django template?

Ans: We can use the range function but there is no range tag or function in Django template.

What does Forloop counter print?

counter indicates how many times the for tag has gone through its loop.


2 Answers

Try this by keeping space around operator

{% if forloop.counter <= 12 or forloop.counter >= 25 %}
like image 145
itzMEonTV Avatar answered Oct 12 '22 14:10

itzMEonTV


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

like image 42
semorale Avatar answered Oct 12 '22 15:10

semorale