【发布时间】:2022-11-29 02:57:15
【问题描述】:
第四个 elif 语句是导致我出现问题的语句。我已将第三个 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 %}
我想要一些 elif 语句,可能是 10 或 12。这可能吗?
【问题讨论】:
-
确实很少有语言接受像
first_hour_d == 'overcast clouds' or 'broken clouds'这样的结构,这里它并没有按照您的想法去做。另一方面,这是一个有效的结构,做你期望的事情:first_hour_d == 'overcast clouds' or first_hour_d == 'broken clouds' -
不怎么读书,我想你需要:
elif a == "a" or a == "aaaa"