Джанго: Не удалось разобрать остаток: '{{' из '{{ - PullRequest
0 голосов
/ 01 октября 2019

Когда я выполняю свой HTML-код, он выдает мне следующую ошибку:

Could not parse the remainder: '{{' from '{{'

Я тоже пытался вложить условия, но я абсолютный новичок в HTML, поэтому я хотел получить эту версию нанаименее правильный, но он не работает ...

{% block content %}
<p align="justify"> So far you donated {{ donated_trees }} Tree(s).  </p>
 {% if treatmentgroup == 'two' or treatmentgroup == 'three' %}
    Your current position is {{ player.end_position }} of {{ anzahlspieler }} for the most donated trees.
{% endif %}

 {% if treatmentgroup == 'two' or treatmentgroup == 'three' and {{ player.rival }} == 0 %}
<P>     No other player has the same.</P>
{% endif %}

 {% if treatmentgroup == 'two' or treatmentgroup == 'three' and {{ player.rival }} == 1 %}
<P>     One other player has the same.</P>
{% endif %}

{% if treatmentgroup == 'two' or treatmentgroup == 'three' and {{ player.rival }} > 1 %}
<P>     {{ player.rival }} other players have the same.</P>
{% endif %}

Ошибка возникает из строки 8 вкл.

Ответы [ 2 ]

2 голосов
/ 01 октября 2019

Вы можете не использовать {{ &hellip; }} в теге шаблона, просто используйте саму переменную:

{% block content %}
<p align="justify"> So far you donated {{ donated_trees }} Tree(s).  </p>
 {% if treatmentgroup == 'two' or treatmentgroup == 'three' %}
    Your current position is {{ player.end_position }} of {{ anzahlspieler }} for the most donated trees.
{% endif %}

 {% if treatmentgroup == 'two' or treatmentgroup == 'three' and <b>player.rival == 0</b> %}
<P>     No other player has the same.</P>
{% endif %}

 {% if treatmentgroup == 'two' or treatmentgroup == 'three' and <b>player.rival == 1</b> %}
<P>     One other player has the same.</P>
{% endif %}

{% if treatmentgroup == 'two' or treatmentgroup == 'three' and <b>player.rival > 1</b> %}
<P>     {{ player.rival }} other players have the same.</P>
{% endif %}
1 голос
/ 01 октября 2019

Ваша проблема в этой строке, а также ответы, как это.

 {% if treatmentgroup == 'two' or treatmentgroup == 'three' and {{ player.rival }} == 0 %}

Когда вы используете переменную в тегах {% %}, вы просто помещаете переменную отдельно, например player.rival, а не {{ player.rival }}.

Полный рабочий код:


{% block content %}
<p align="justify"> So far you donated {{ donated_trees }} Tree(s).  </p>
 {% if treatmentgroup == 'two' or treatmentgroup == 'three' %}
    Your current position is {{ player.end_position }} of {{ anzahlspieler }} for the most donated trees.
{% endif %}

 {% if treatmentgroup == 'two' or treatmentgroup == 'three' and player.rival == 0 %}
<P>     No other player has the same.</P>
{% endif %}

 {% if treatmentgroup == 'two' or treatmentgroup == 'three' and player.rival == 1 %}
<P>     One other player has the same.</P>
{% endif %}

{% if treatmentgroup == 'two' or treatmentgroup == 'three' and  player.rival > 1 %}
<P>     {{ player.rival }} other players have the same.</P>
{% endif %}
...