Как условно отобразить html-элемент в шаблоне Django
Я использую сервер 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>
Вы делаете это с помощью 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 %}