我需要创建一组带有 int 值的下拉框(例如:1-3),它们在 mongodb 中保存并正确读取。第一次会话后,我想将他们存储的值放在下拉列表中
server.py 上的函数:
@get('/my_url')
def form():
#get the last entry in database, the most updated one
for my_document in db.mydb.find():
pass
return template('asset_form',**my_document)
asset_form.tpl(部分):
<h1>My site</h1>
<hr>
<h3>Asset: <input name="name1" type="text" value="Mail Server" input disabled /> </h3>
{{dic_field1}}
{{dic_field2}}
{{my_document}}
<table style="width:100%">
<tr>
<th>Col1</th>
<th>Col2</th>
<th>Col3</th>
<th>Col4</tj>
</tr>
<td>
<form method="POST" action="/the_post_url">
<br/>
Number of day(s):<select name = dic_field1>
%if{{dic_field1}} == 1:
<option value="1" selected >1</option>
%else:
<option value="1">1</option>
%end
%if {{dic_field1}} == 2:
<option value="2" selected >2</option>
%else:
<option value="2">2</option>
%end
%if {{dic_field1}} == 3:
<option value="3" selected>3</option>
%else:
<option value="3">3</option>
%end
我可以在 python 服务器中获取值(正确打印它们)。my_document 字典有字段:dic_field1 和 dic_field2,
在模板中,变量“{{my_document}}”输出错误:
NameError("name 'my_document' 未定义",)
其中 dic_field1 和 dic_field2 输出正确。
拥有变量是不够的,因为在“if”中使用它们时,输出如下:
TypeError("不可散列的类型:'set'",)
泛舟湖上清波郎朗
相关分类