搜索结果显示在表单下方的同一页面上后,我希望搜索词仍然留在搜索框中,而不是被抹去。我的搜索表单模板:
<form class="search" method="post">
<input name="query" type="text" style="max-width:700px" placeholder="Search over wbkg.." id="query" autocomplete="on" required>
<button type="submit"><i class="fa fa-search"></i></button>
<input type="radio" name="options" id="kmatch" value="kmatch" checked="checked">match </input>
<input type="radio" name="options" id="kextraction" value="kextraction"> extraction </input>
</form>
烧瓶视图函数:
@bp.route('/wbkg', methods=('GET', 'POST'))
def wbkg():
if request.method == 'POST':
query = request.form['query']
search_type = request.form['options']
results = search(query, search_type)
return render_template('nlp/wbkg.html', items=results)
return render_template('nlp/wbkg.html')
那可能吗?
是的,只需将其与搜索结果一起传回:
return render_template('nlp/wbkg.html', items=results, query=query)
然后在模板中显示(如果存在):
<input name="query" type="text" id="query" autocomplete="on" value="{{query}}" required>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句