Django:无法解析其余部分:“ {{{

时间:2019-10-01 16:52:52

标签: html django if-statement error-handling nested

我执行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 个答案:

答案 0 :(得分:2)

您可以在模板标签内使用{% 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 %} ,而只需使用变量本身即可:

visit

答案 1 :(得分:1)

您的问题就在这一行以及类似的答案中。

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