【发布时间】:2020-07-11 01:18:31
【问题描述】:
我在使用 Flask 框架使用模板生成一些 html 页面时遇到了问题(这是我第一次使用 Flask 或任何框架)
我正在使用通常的 render_template 调用来调用模板
return render_template("index.html", rec_list = rs_rec_list, type_list = rs_type_list)
rs_rec_list 和 rs_type_list 采用标准 python 列表格式
然后我的模板有以下代码部分:
<div class = "new_record_column">
<div class="leftcolumn">
<div class="new_record_header">
ADD NEW RECORD
</div>
<div class="new_record_container">
<label for "refnum">Ref No. </label> 
<input type="text" id="refnum" size="30">    
<select id="rec_type">
{% for type_item in type_list %}
<option value = loop.index> {{type_item}} </option>
{% endfor %}
</select>    
<button>GO</button>
</div>
</div>
</div>
<table>
<tr>
<th>Reference No.</th>
<th>Header 1</th>
<th>Header 2</th>
<th>Type</th>
<th>Operator</th>
<th>Comments</th>
<th>Date/time</th>
</tr>
<tr>
{% for rec_item in rec_list %}
<td> {{rec_item}} </td>
{% endfor %}
</tr>
</table>
我遇到的问题是填充选择列表的第一个 for 循环正常工作,但填充表中列的第二个 for 循环似乎没有做任何事情。我很确定这很明显,但我现在可能已经盯着它看太久了:)
【问题讨论】: