我有mongo文档数据示例(供参考):
从视图为:
data=wordscollection.find({'word':word})
return render_template('wordsearch.html',data=data)
在模板中,我仅将其作为第一个索引,不检查示例或同义词是否为空:
{% for word in data %}
<tr>Meaning :{{ word['meanings'][0]['def'] }}</tr><br>
<tr>Example :{{ word['meanings'][0]['example'] }}</tr><br>
<tr>Parts Of Speech :{{ word['meanings'][0]['speech_part'] }}</tr>
{% endfor %}
输出为:
1)如何将所有索引结果显示为
meaning1: def1
speechpart1: speech_part1
example1: //2)writing condition for this to show if exits
synonym: //2)writing condition for this to show if exits
Meaning2: def2
........
........
我试了两次运气如下:
{% for word in data if word['meanings'][0]['example'] %}
但这也不管用
谢谢你的帮助,蒂亚
同义词更新答案
您还必须使用嵌套for循环来迭代
meanings
,并在之前检查空值相关问题 更多 >
编程相关推荐