1 回答

TA贡献1818条经验 获得超3个赞
看来您并不真正了解变量在瓶子中的工作原理。运行原始 python 代码时,不需要大括号。只有在将数据值注入 html 时才需要它们。
也只需将结果发送到模板并在模板内处理它们。这样您就不必弄乱源代码,而只需专注于您的模板。
@get('/my_url')
def form():
#get the last entry in database, the most updated one
my_document = db.mydb.find()
return template('asset_form', mydocument = my_document)
资产
%dic_field1 = mydocument['dic_field1']
%dic_field1 = mydocument['dic_field2']
%dic_field1 = mydocument['dic_field3']
<h1>My site</h1>
<hr>
<h3>Asset: <input name="name1" type="text" value="Mail Server" input disabled /> </h3>
{{dic_field1}}
{{dic_field2}}
{{dic_field3}}
<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
添加回答
举报