{% for item in res%}
<tbody>
<tr>
<th scope="row">{{ item['_source']['lang'] }}</th>
<td>{{ item['_source']['id'] }}</td>
<td>{{ item['_source']['date'] }}</td>
<td>{{ item['_source']['full_text']}}</td>
<td>{{ item['_source']['user']['name']}}</td>
<td>{{ item['_source']['user']['screen_name']}} </td>
<td>{{ item['_source']['user']['location']}} </td>
<td>{{ item['_source']['user']['id']}} </td>
{% for i in item['_source']['entities']['user_mentions'] if i["screen_name"] %}
<td> {{ i["screen_name"] }} <td>
{% else %}
<td> None <td>
{% endfor %}
</tr>
</tbody>
{%endfor%}
您的HTML有多个问题。 您没有关闭标记,并且循环中间有一个随机的{%else%}。 根据我对您的问题的理解,您会希望将其格式化为:
{% for item in res %}
<tbody>
<tr>
<th scope="row">{{ item['_source']['lang'] }}</th>
<td>{{ item['_source']['id'] }}</td>
<td>{{ item['_source']['date'] }}</td>
<td>{{ item['_source']['full_text'] }}</td>
<td>{{ item['_source']['user']['name'] }}</td>
<td>{{ item['_source']['user']['screen_name'] }} </td>
<td>{{ item['_source']['user']['location'] }} </td>
<td>{{ item['_source']['user']['id'] }} </td>
<td>
{% for i in item['_source']['entities']['user_mentions'] if i["screen_name"] %}
{{ i["screen_name"] }}<br>
{% endfor %}
</td>
</tr>
</tbody>
{% endfor %}