Nikhil Sardana
Nikhil Sardana

Reputation: 365

Could not parse the remainder for boolean operators in django template

How can I use a boolean operator 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'

Upvotes: 11

Views: 16333

Answers (3)

Abdul Aziz Barkat
Abdul Aziz Barkat

Reputation: 21807

The parser used by Django templates fails to parse the values if there is a lack of whitespace around the operators. There was a ticket #27022 opened on Django's issue tracker but it has been marked as "wontfix" in an effort to enforce a consistent style in templates.

Hence you need to update your code and add spaces around the operators:

{% if forloop.counter <= 12 or forloop.counter >= 25 %}

Upvotes: 0

semorale
semorale

Reputation: 21

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

Upvotes: 2

itzMEonTV
itzMEonTV

Reputation: 20349

Try this by keeping space around operator

{% if forloop.counter <= 12 or forloop.counter >= 25 %}

Upvotes: 19

Related Questions