Could not parse the remainder
Asked Answered
S

8

37

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

Sikorsky answered 25/8, 2010 at 2:57 Comment(0)
U
61

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 %}
Unceasing answered 25/8, 2010 at 3:9 Comment(1)
This can also happen if you use {{ }} where you should use {% %}Clockmaker
V
19

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' %}">
Vampirism answered 7/2, 2017 at 22:47 Comment(0)
B
1

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).

Barrus answered 15/9, 2022 at 1:48 Comment(0)
K
1

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 ==

Kendyl answered 4/2, 2023 at 18:1 Comment(0)
G
1

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

Gouveia answered 27/3, 2023 at 1:38 Comment(0)
G
0
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>
Gurtner answered 30/9, 2019 at 9:29 Comment(0)
C
0

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

Civilize answered 12/2, 2021 at 17:2 Comment(1)
This is not directly related to the question but it gives the same error. I have the same problem and It was so helpful. Thus I give it thumb up.Portauprince
C
0

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

Cyrus answered 13/6 at 7:18 Comment(2)
Your answer is not really clear, please double check your explanation and grammarJallier
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Galenic

© 2022 - 2024 — McMap. All rights reserved.