I am confused about passing data from database (mongodb) to html.
I have python code in "init.py" that queries database using while logic - see below code snippet:
from pymongo import MongoClient
from flask import Flask, render_template
@app.route("/snapshot")
def pymongo_query():
db=client.collection
months=[1,2,3,4,5,6,7,8,9,10,11,12]
while months:
mon=months.pop()
query=list(db.collection.find({args}))
query=query[0]
month=query['month']
item_1=query['item_1']
item_2=query['item_2']
What this codes does is it goes through each month represented by number in list and queries database for the respective month. I use while loop to go over months. In Python I would use print at the end of loop to output result.
How do I output data into html using jinja2? I was wondering if I need to have while logic in jinja or keep it as I have it right now in init.py file above.