I'm able to retrieve required value from MongoDB individually and also able to print same values but unable to return all those values to HTML page. When I try to return those values I'm able to see only first value though I have used for loop in jinja.
My code is as follows:
@app.route('/webhookdisplay', methods=['POST', 'GET'])
def webhooksdis():
collection10 = db['webhooks']
a = collection10.find({"name": "abc"}, {'_id': 0, 'recorded_at':0, 'expiry_time': 0, 'version': 0, 'created_at': 0, 'account_id': 0, 'device_id': 0})
for i in collection10.find({}):
d = i.get('data', {}).get('geometry', {}).get('coordinates')
print(d)
name = i.get('data', {}).get('geofence_metadata', {}).get('name')
print(name)
return render_template("webhooks.html", name = name, a = a, d =d)
In the above code name has None values also, so when I try to return it individually shows TypeError: 'NoneType' object is not iterable. Suppose if I return those values which dowsn't have None values it gets returned but displays only first value.
HTML code
{% for i in d %}
{{ i }}
{% endfor %}<br />
This jinja works for all values but I require for individual values which I'm retrieving in flask:
<table>
<th>
{% for item in a %}
</th>
<tr>
<td><th> {% for key, value in item.items() %} </th> </td>
<td><span>{{ key }} : {{ value }}</span> </td>
<br />
<td>{% endfor %}</td>
<td>{% endfor %}</td>
</tr>
</table>
**Expected Output** All values including None values should be returned which I'm retrieving in flask so that I can render in HTML page