我在使用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循环似乎没有任何作用。我很确定这是显而易见的,但是我可能已经盯着它看了太久,看不到它了:)
答案 0 :(得分:1)
您是否检查过rec_list
是否为空?