首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >django表中的If语句-模板

django表中的If语句-模板
EN

Stack Overflow用户
提问于 2021-07-05 17:59:43
回答 2查看 545关注 0票数 1

说我们在模板中有表

代码语言:javascript
复制
<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语句?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2021-07-05 18:00:54

由于您已经在模板标记中,所以不应该对变量使用花括号({{ … }}),因此:

代码语言:javascript
复制
{% if student.academic_status == "promoted" %}
    …
{% endif %}
票数 1
EN

Stack Overflow用户

发布于 2021-07-05 18:08:13

在Django模板中添加if语句的正确方法

跟我来!

if语句

代码语言:javascript
复制
{% if condition %}

   {{here you add the key that you using in the views page exactly context}}

{% endif %}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68260365

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档