【发布时间】:2015-08-20 19:09:44
【问题描述】:
我有一个表格,我正在用模板中的 for 循环列表中的信息填充该表格。一旦达到特定值,我想结束当前表并创建一个新表。我写了这个打印表中的所有值但不输入 if 语句:
<table class="table">
{% for x, y, z in defStats %}
<tr class = "info">
<td>
{{ x }}
</td>
<td>
{{ y }}
</td>
<td>
{{ z }}
</td>
</tr>
{% if x == " " %}
<p>HERE</p>
</table>
<table>
{% endif %}
{% endfor %}
</table>
我要查找的字符是一个空字符串。我什至尝试了一个 if 语句,它保证评估为 true,并且根本没有进入 if 语句:
<table class="table">
{% for x, y, z in defStats %}
<tr class = "info">
<td>
{{ x }}
</td>
<td>
{{ y }}
</td>
<td>
{{ z }}
</td>
</tr>
{% if x == x %}
<p>HERE</p>
</table>
<table>
{% endif %}
{% endfor %}
</table>
在这两种情况下,根本就没有输入 if 语句。不知道怎么回事,谢谢。
【问题讨论】:
-
在第二种情况下,您确定正在使用更新的模板吗?首先,空字符串是
'',而不是' '(这是一个空格)。 -
我无法弄清楚您希望采取的方法背后的原因,也许如果我们知道您的目标,我们可能会采用不同的方法,可能同样有帮助
-
这是一个模板问题,我很抱歉刚刚得到它的工作
标签: django if-statement django-templates