5 回答

TA貢獻1725條經(jīng)驗 獲得超8個贊
首先,在django 視圖函數(shù)中,傳遞 obj_list = [1, 2, 3] 類似這樣的一個列表。def show_data(request):
obj_list = [1, 2, 3]
pass
return render_to_response('index.html', {'obj_list': obj_list})
然后在 index.html 模板文件中,部分代碼如下
<select>
{% for obj in obj_list %}
<option value ="{{ forloop.counter }}">{{ obj }}</option>
{% endfor %}
</select>
這樣,模板就能自動根據(jù)傳遞過來的數(shù)據(jù),進行顯示。

TA貢獻1900條經(jīng)驗 獲得超5個贊
首先,在django 視圖函數(shù)中,傳遞 obj_list = [1, 2, 3] 類似這樣的一個列表。def show_data(request): obj_list = [1, 2, 3] pass return render_to_response('index.html', {'obj_list': obj_list}) 然后在 index.html 模板文件中
添加回答
舉報