【问题标题】:how to conditional render html element in a Django template如何在 Django 模板中条件渲染 html 元素
【发布时间】:2022-01-19 16:52:20
【问题描述】:

我正在使用 django 服务器发送用户电子邮件通知,我遇到了一个地方,我需要说明这个元素是否不存在在文本下方添加边距/空格

 <tr style="padding:0;margin:0;" height="30">
     <td width="190" style="font-family:Roboto;color:#000000;font-weight:bold">Date</td>
     <td width="400" style="font-family:Roboto;color:#000000;">{{ processed_datetime|date:"d/m/Y H:i" }}</td>

<!--I want to say here if  there is no other party email add this element underneath  -->

{% if ! counterpart.email} <!--not sure about this line syntax -->
 <tr style="padding:0;margin:0;" height="20">
   <td width="190" height="20" style="font-family:Roboto;color:#000000;font-size:24px;line-height:32px;"></td>
 </tr>

【问题讨论】:

    标签: django templates django-templates


    【解决方案1】:

    您使用not 执行此操作,所以:

    {% if not counterpart.email %}
      <tr style="padding:0;margin:0;" height="20">
        <td width="190" height="20" style="font-family:Roboto;color:#000000;font-size:24px;line-height:32px;"></td>
      </tr>
    {% endif %}

    【讨论】:

      猜你喜欢
      • 2021-05-01
      • 1970-01-01
      • 2021-11-20
      • 2018-01-17
      • 1970-01-01
      • 2014-05-12
      • 2017-02-11
      • 2022-01-11
      • 2016-11-13
      相关资源
      最近更新 更多