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
添加回答
舉報