LoveTW
LoveTW

Reputation: 3832

Could not parse the remainder

i want to compare num and {{buildSummary_list.number}}, but why it is not work? And i got an error

Could not parse the remainder: '{{buildSummary_list.number}}' from '{{buildSummary_list.number}}'"...

{% for num in buildSummary_list.paginator.page_range %}
    {% ifequal num {{buildSummary_list.number}} %}
        <b>{{num}}</b>
    {% endifequal %}
    {% ifnotequal num {{buildSummary_list.number}} %}
        <a href="?page={{num}}"><b>{{num}}</b></a>
    {% endifnotequal %}

{% endfor %}

I want to make the pagination have effect: pre << 1 2 3 4 5 6 >> next

I my code can run, can it make this effect? thanks:D

Upvotes: 37

Views: 145627

Answers (8)

Ravi Nikam
Ravi Nikam

Reputation: 1

Give the space to both side of your Html (jinja) element like this:

{% if res.gender*==*'F' %} checked{% endif %}

for Display purpose i give you a * you have to give space their

Upvotes: 0

Rajeshwar Sharma
Rajeshwar Sharma

Reputation: 31

When you are dealing with comparison operator == within templates, make sure you have spaces before and after == operator. This could be one of the reason for above error. For ex. category.slug == c.slug

Upvotes: 1

Hossein Shafiei
Hossein Shafiei

Reputation: 645

thats so easy you should not write like this

{% if foo=='bar' %}
<!-- do something -->
{% endif %}

you should write your code like this

{% if foo == 'bar' %}
<!-- do something -->
{% endif %}

pay attention to the space before ==

Upvotes: 1

Bedaprakash Mallick
Bedaprakash Mallick

Reputation: 11

The django. DjangoTemplates template backend is unable to parse a comparison operator when there is no whitespace around the operator using builtin tag if:

{% if foo=='bar' %}
<!-- do something -->
{% endif %}

raises TemplateSyntaxError at url

Could not parse the remainder: '=='bar'' from 'foo=='bar''

At least one space is required on both sides of the == operator (So foo =='bar' and foo== 'bar' throws Could not parse the remainder: '=='bar'' from '=='bar'' and Could not parse the remainder: '==' from 'foo==', respectively). More than one space is acceptable. This seems to affect the following boolean operators: ==, !=, <, >, <=, >=. My guess is the boolean expression tokenizer in DjangoTemplates first tries split(' ') then ultimately evals [0][1][2] (but I haven't actually looked at the source to verify this).

Upvotes: 1

Shubham Mokashi
Shubham Mokashi

Reputation: 29

Could not parse the remainder: '>0' from 'forloop.counter>0'

I got this error !!!

if its a TemplateSyntaxError then just correct your spaces between the code For example:

( wrong statement ) {% if forloop.counter|divisibleby:3 and forloop.counter>0 and not forloop.last %}

( right statement ) {% if forloop.counter|divisibleby:3 and forloop.counter > 0 and not forloop.last %}
space between ( forloop.counter > 0)

this worked for me

Upvotes: 0

Mr Coder
Mr Coder

Reputation: 523

django 2.2 relative URL

**Correct**

<a href="{% url 'urlapp:other' %}">go to other page </a>
<br/>
<a href="{% url 'admin:index' %}"> admin page</a>

**error inccorect code some white space still get same error ** 

<a href="{% url 'urlapp:other' %}">go to other page </a>
<br/>
<a href="{% url 'urlapp: other' %}">go to other page </a>
<br/>
<a href="{% url 'admin:index' %}"> admin page</a>
<br/>
<a href="{% url 'admin':index %}"> admin page</a>

Upvotes: 0

DevB2F
DevB2F

Reputation: 5075

I got this error when I forgot the '' around the path to a static file

This gave the error:

 <link rel='stylesheet' href="{% static css/style.css %}">

This fixed the error:

 <link rel='stylesheet' href="{% static 'css/style.css' %}">

Upvotes: 19

Ned Batchelder
Ned Batchelder

Reputation: 375484

Inside a {% %} tag, variables aren't surrounded by {{. Try this:

{% ifequal num buildSummary_list.number %}

Also, it looks like your two comparisons can be joined with an else:

{% for num in buildSummary_list.paginator.page_range %}
    {% ifequal num buildSummary_list.number %}
        <b>{{num}}</b>
    {% else %}
        <a href="?page={{num}}"><b>{{num}}</b></a>
    {% endifequal %}
{% endfor %}

Upvotes: 61

Related Questions