5 回答

qq_遁去的一_1
TA貢獻1725條經驗 獲得超8個贊
首先,在django 視圖函數中,傳遞 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>
這樣,模板就能自動根據傳遞過來的數據,進行顯示。

梵蒂岡之花
TA貢獻1900條經驗 獲得超5個贊
首先,在django 視圖函數中,傳遞 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 模板文件中
添加回答
舉報
0/150
提交
取消