2
我開始閱讀一些燒瓶應用程序編程,我一直試圖讓下拉菜單工作,但到目前爲止,我沒有運氣。我想要做的是,當用戶從第一個下拉列表中選擇食物類型時,它應該從數據庫中獲取相應的列表並填充第二組下拉列表。我不知道如何在做出選擇後發送快速請求。我真的不明白這裏應該做什麼。燒瓶動態相關下拉列表
<body>
<div>
<form action="{{ url_for('test') }}" method="POST">
<div>
<label>Food:</label>
<select id="food" name="food" width="600px">
<option SELECTED value='0'>Choose your fav food</option>
{% for x in food %}
<option value= '{{ x }}'>{{x}}</option>
{% endfor %}
</select>
<!-- After a selection is made, i want it to go back to the database and fectch the results for the below drop box based on above selection -->
</div>
<div>
<label>Choose Kind of Food:</label>
<select id="foodChoice" name="foodChoice" width="600px">
<option selected value='0'>Choose a kind</option>
{% for x in foodChoice %}
<option value= '{{ x }}'>{{x}}</option>
{% endfor %}
</select>
</div>
<div>
<input type="submit">
</div>
</form>
</div>
app.html
@app.route('/', method = ['GET', 'POST'])
def index():
foodList = [ i.type for i in db.session.query(FoodType)]
return render_template('main.html', food=foodList)
@app.route(/foodkind', method = ['GET', 'POST'])
def foodkind():
selection = request.form['foodChoice']
foodKind = [ i.kind for i in db.session.query(FoodType).filter(FoodKind == selection)]
return render_template('main.html', foodChoice = foodKind)
我已經看了很多問題,我還沒有找到任何簡單的,這將有助於我。如果有人能爲我演示一個代碼,這將是一件好事,所以我可以從中學習。