[英]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.