我嘗試使用網頁上的數據導入製作幾張表格!我用Python來使用Flask-Jinja。 例如,我有這樣的雙重名單:如何在Flask-Jinja列表中使用列表蟒蛇Python
list = [[{'pricebb': 1199.99, 'model': 'model1', 'pricebh': 1199, 'pricea': 1299}, {'pricebb': 1199.99, 'model': 'model2', 'pricebh': 1199, 'pricea': 1299}, {'pricebb': 1499.99, 'model': 'model3', 'pricebh': 1499, 'pricea': 1599}], [{'pricebb': 399.99, 'model': 'model4', 'pricebh': 459, 'pricea': 499}, {'pricebb': 599.99, 'model': 'model5', 'pricebh': 669, 'pricea': 699}, {'pricebb': None, 'model': 'model6', 'pricebh': 899, 'pricea': 999}]]
我想將它與環分離並在一個頁面上創建2個不同的表。 如果我使用Python與列表[0]我得到1-ST子表,但是當我嘗試在瓶:
{% for post in posts %}
<p>{{post[0]}}</p>
{% endfor %}
還給我 - MODEL1和model4)爲什麼它的發生?我如何從列表中獲得1-st子列表?你有什麼想法!?謝謝!
run1()
list= sqlselect()# here is array from DB
a = list # its a list sample that I posted above
@FlaskApp2.route('/', methods=('Get', 'Post'))
@FlaskApp2.route('/index')
def index():
user = {'nickname': 'parser'} # fake user
return render_template("index.html",
title='Web',
user=user,
posts=list, describe=des)
下面是index.html的:
<table>
<caption>products compare list ({{item}})</caption>
<thead>
<tr>
<th>qqq.com</th>
<th>Price</th>
<th>qqq.com</th>
<th>qqq.com</th>
</tr>
</thead>
{% for post in posts %}
<p>{{post[0]}}</p>
{% endfor %}
</table>
可以共享整個程序 – Rednivrug
更新........ – TheRutubeify