如果在 Django html 模板上有条件
If condition on Django html Template
jobseqno=P567890
<td>
{% if jobseqno|first:"P" %}** <a href="{{ url }}{{ jobseqno }}" target="_blank">{{ jobseqno}}</a>{% endif %}
</td>
以上附加代码无效请帮帮我!!
您可以通过以下方式检查:
{% if <strong>'P' == jobseqno|first</strong> %}
…
{%endif %}
如果您要过滤 QuerySet
,您应该在数据库查询中过滤它,所以在 视图 中,而不是模板中。
jobseqno=P567890
<td>
{% if jobseqno|first:"P" %}** <a href="{{ url }}{{ jobseqno }}" target="_blank">{{ jobseqno}}</a>{% endif %}
</td>
以上附加代码无效请帮帮我!!
您可以通过以下方式检查:
{% if <strong>'P' == jobseqno|first</strong> %}
…
{%endif %}
如果您要过滤 QuerySet
,您应该在数据库查询中过滤它,所以在 视图 中,而不是模板中。