[英]Weird HTML select tag behavior with python flask
具有數據綁定的HTML
Location:<br>
{% for item in data %}
<select name="location">
<option value={{ item[0] }}>{{ item[0] }}</option>
</select>
{% endfor %}
后端
@app.route('/events', methods = ['post', 'get'])
def events():
#data = ['loc1','loc2','loc3']
cursor = conn.cursor()
cursor.execute('SELECT * FROM location')
rows = cursor.fetchall()
data = [row for row in rows]
cursor.close()
return render_template('events.html', data = data)
當我render_template並傳遞數據時,它從數據庫中檢索locations
列表,並將其作為選擇的選項。
現在看起來像這樣
它應該具有4個選項的選擇列表(?),但是其中只有4個帶有on選項的單獨選擇列表。
我怎樣才能解決這個問題?
您需要遍歷選擇選項,而不是遍歷整個選擇塊:
Location:<br>
<select name="location">
{% for item in data %}
<option value={{ item[0] }}>{{ item[0] }}</option>
{% endfor %}
</select>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.