Usually I did many times without problems but now it's different and I don't know why .
I'm just trying to display a list on html page using Flask and Jinja2.
And here is my piece of code.
__init__.py
bpPortfolioList = Blueprint('portfolio', __name__)
@bpPortfolioList.route('/list', methods=['GET', 'POST'])
@is_log_in
def plist():
portfolio = None
if session['profile'] == 1:
print('agent')
portfolio = mongo.db.users.find({"agentid": session['userid']}, {"portfolio": 1})
for p in portfolio:
print(p)
return render_template('portfolio/list.html', portfolios=portfolio)
I have catch the output of portfolio and here is the result :
{'_id': 10, 'portfolio': {'id': 8476, 'description': '', 'mode': 'Closed', 'accounts': [{'id': 123456, 'account_type': 'None', 'category': '1', 'owner': None, 'ratio': 100, 'status': '1'}]}}
{'_id': 1}
{'_id': 11, 'portfolio': {'id': 4983, 'description': '', 'mode': 'Closed', 'accounts': []}}
{'_id': 13, 'portfolio': {'id': 1226, 'description': '', 'mode': 'Closed', 'accounts': []}}
{'_id': 15, 'portfolio': {'id': 8786, 'description': '', 'mode': 'Closed', 'accounts': []}}
{'_id': 19, 'portfolio': {'id': 7995, 'description': '', 'mode': 'Closed', 'accounts': []}}
Then the HTML :
<tbody>
{% for p in portfolios %}
<tr>
<td>{{ p.id }}</td>
<td>{{ p.mode }}</td>
{% for c in p.accounts %}
<td>{{ c.id }}</td>
<td>{{ c.status }}</td>
<td>{{ c.ratio }}</td>
{% endfor %}
</tr>
{% endfor %}
</tbody>
At the result I got nothing, except the table header
Any idea what the problem ?
Thanks for your help.
mongo.db.users.finda generator? If so all your contents are consumed by theforstatement. Also, your template may in fact not match up with the data structure, as what is yielded should be accessible viap['portfolio']['id']and so on.portfolioassignment) and see if you get twice the output.