python - django-templates 中的表中的 if 语句
问题描述
假设我们在模板中有表格
<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 语句
解决方案
由于您已经在模板标签中,因此您不应该对变量使用大括号 ( {{ … }}
),因此:
{% if student.academic_status == "promoted" %}
…
{% endif %}
推荐阅读
- ruby-on-rails - 安装后不显示ckeditor
- azure-cosmosdb - CosmosDB 的 Gremlin - 无法在非原始类型 GraphTraversal 上创建 ValueField
- python-3.x - Facebook Messenger bot 的日期选择器 webview - 无法将字段值带回 bot 的输入字段
- php - 检查点防火墙实施后的会话交换
- java - FileReader 和 ActionListner 之间的同步问题,FileReader 在我可以给他任何勇气之前给出空指针;
- apache-spark - 从长转换为时间戳以插入数据库
- docker - 从 jwilder/nginx-proxy 提供静态文件
- xslt - xsl:text 元素中的空格
- mysql - SQL:如何通过连接从不同的表中获取多行?(初学者的问题)
- dialogflow-es - 在谷歌助手中更改表格的背景颜色