简体   繁体   English

即使条件为真,Jinja elif 也无法正常工作

[英]Jinja elif not working even though condition is true

The fourth elif statement is the one causing me the issue.第四个 elif 语句是导致我出现问题的语句。 I have swapped the third elif statement with the fourth and every time the fourth is in third place it works.我已将第三个 elif 语句与第四个交换,每次第四个排在第三位时它都有效。

{% block content%}

{% load static %}
<link rel="stylesheet" href="{% static 'css/home_page.css' %}">
<link rel="stylesheet" href="{% static 'css/home_w_d_cs.css' %}">


{% if first_hour_d == 'clear sky' and time_of_day == True %} <!-- day == True means day -->

    <div class="side-hour-icon">
        <img src="{% static 'images/sunny-black.png' %}" alt="" width="55" height="50">
    </div>


{% elif first_hour_d == 'clear sky' and time_of_day == False %} <!-- day == False means night -->
    <div class="side-hour-icon">
        <img src="{% static 'images/clear-night-black.png' %}" alt="" width="55" height="50">
    </div>

{% elif first_hour_d == 'overcast clouds' or 'broken clouds' %}
    <div class="side-hour-icon">
        <img src="{% static 'images/cloudy2.png' %}" alt="" width="55" height="50">
    </div>
    
{% elif first_hour_d == 'few clouds' or 'scattered clouds' %}
    <div class="side-hour-icon">
        <img src="{% static 'images/few-clouds-black.png' %}" alt="" width="55" height="50">
    </div>


{% endif %}

{% endblock %}

I want to have a few elif statements, maybe 10 or 12. Is this possible?我想要一些 elif 语句,可能是 10 或 12 个。这可能吗?

You can't do:你不能这样做:

{% elif first_hour_d == 'overcast clouds' or 'broken clouds' %}

because the second string will always evaluate to True .因为第二个字符串将始终评估为True

You must do:你必须这样做:

{% elif first_hour_d == 'overcast clouds' or first_hour_d == 'broken clouds' %}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 即使条件为真,Python也会跳过 - Python is skipping if condition even though true 即使条件为真,具有 else 条件的 For 循环也会运行 - For-loop with else condition runs even though the condition is true If 语句仅运行 else 条件,即使 if 条件为真 - If statements only runs the else condition even though the if condition is true 如果即使满足条件,在for循环中也不起作用 - If in for-loop not working even though the condition is satisfied 即使条件评估为true,代码也会跳过循环 - Code skips the loop even though the condition evaluates to true 即使在django模板中满足条件,if语句也无法评估为true - if statement fails to evaluate to true even though condition is met in django template Python True / False if / elif / else条件 - Python True/False if/elif/else condition 即使我创建了两个单独的列表,为什么if条件为真 - Even though I have created two seperate lists, why is the if condition true 为什么即使条件逻辑始终为真,异步任务的 done() 方法上的 while 循环也会中断? - Why the while loop on asyncio task's done() method break even though the condition logic is always true? 为什么即使 python 中的条件为真,我的 while 语句的主体也不打印 - Why does does the body of my while statement not print even though the condition is true in python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM