说我们在模板中有表
<table class="table">
<thead>
<tr>
<th>Status</th>
</tr>
</thead>
<tbody>
{% for student in students %}
<tr>
{% if {{student.academic_status}}=="promoted" %}
<td class=text-success>promoted</td>
{% endif %}
</tr>
{% endfor %}
</tbody>
</table>那么,是否可以在django-templates中的表中使用if语句?
发布于 2021-07-05 18:00:54
由于您已经在模板标记中,所以不应该对变量使用花括号({{ … }}),因此:
{% if student.academic_status == "promoted" %}
…
{% endif %}发布于 2021-07-05 18:08:13
在Django模板中添加if语句的正确方法
跟我来!
if语句
{% if condition %}
{{here you add the key that you using in the views page exactly context}}
{% endif %}https://stackoverflow.com/questions/68260365
复制相似问题