在我的模板中,如果通知项为“无”,我会尝试隐藏警报按摩 div

问题描述 投票:0回答:1
         {% if not notfication in alert %}
            <div style=" background: no-repeat; ">
                <div class="">
                    <span>None</span>
                
                </div>
            </div>
        {% else %}
            <div class="marquee-area">
                <div class="marquee-wrap">
                    {% for notfication in alert %}
                    <span>{{ notfication.title }}</span>
                    {% endfor %}
                </div>
            </div>
        {% endif %}

当我尝试测试它时,无论是否有数据,我都没有收到她的文字

django django-models django-templates
1个回答
0
投票

检查

alert
的真实性:

{% if not alert %}
    <div style=" background: no-repeat; ">
        <div class="">
            <span>None</span>
        
        </div>
    </div>
{% else %}
    <div class="marquee-area">
        <div class="marquee-wrap">
            {% for notification in alert %}
            <span>{{ notification.title }}</span>
            {% endfor %}
        </div>
    </div>
{% endif %}

然而,通常人们使用正逻辑:

{% if alert %}
    <div class="marquee-area">
        <div class="marquee-wrap">
            {% for notification in alert %}
            <span>{{ notification.title }}</span>
            {% endfor %}
        </div>
    </div>
{% else %}
    <div style=" background: no-repeat; ">
        <div class="">
            <span>None</span>
        
        </div>
    </div>
{% endif %}
© www.soinside.com 2019 - 2024. All rights reserved.