我有一个python脚本,它可以抓取一些不同影院的电影页面,并使用flask在html页面中显示结果。我从我的python脚本中传递了一个列表,该列表至少包含一个元素(影院的名称),然后遍历列表的其余部分(todays )并打印出来。
在html中,我想检查这个列表的长度。如果list =1,我想打印一个文本,说明没有任何内容可用。这是我的html代码
<div class="theater">
<div class="row_header">
{{ my_theater[0] }}
</div>
<div class="row_sub_header">
Opening at 11am
</div>
{% if my_theater|length == 1 %} {{ my_theater.append("No movies available today") }} {% endif %} {% for m in my_theater[1:] %}
<div class="row">
<div class="cell">
{{ m }}
</div>
</div>
{% endfor %}
<div class="row_sub_header2">
<p>Price: 10 USD</p>
</div>
</div>And this is the html output (screenshot):
为什么在html中显示"none“,如何删除它?
发布于 2020-03-15 07:51:43
如果分别传递my_theater (作为单个值)和my_movies (作为可能为空的列表),这个问题会变得容易得多。去掉标记,Jinja2部件将如下所示
{{ my_theater }}
{% for movie in my_movies %}
{{ movie }}
{% else %}
No movies available today
{% endfor %}https://stackoverflow.com/questions/60688326
复制相似问题