我想使用 djangoifequal
and else
判断变量是否等于的标签80
or 22
。所以,这是代码:
{% if firewalls %}
<thead>
<tr>
<th>IP address</th>
<th>Function</th>
</tr>
</thead>
{% endif %}
<tbody>
{% for firewall in firewalls %}
<tr>
<td>{{ host_ip }} : {{ firewall.from_port }}</td>
{% ifequal firewall.to_port 22 %} <td>Ssh Service</td>
{% ifequal firewall.to_port 80 %} <td>Web Service</td>
{% else %} <td>Unknown Service</td>{% endifequal %}{% endelse %}
</tr>
{% endfor %}
错误是Invalid block tag: 'endelse', expected 'else' or 'endifequal'
。有人可以帮助我吗?多谢!
ifequal 标记的替代方法是使用 if 标记和 == 运算符。屈服于 '==' 运算符的幂:
{% if firewall.to_port == 20 %}
<td>Ssh Service</td>
{% elif firewall.to_port == 80 %}
<td>Web Service</td>
{% else %}
<td>Unknown Service</td>
{% endif %}
这样,您还可以节省代码处理时间,因为它不会评估每个端口号的所有 if 条件。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)