我试图得到一个选择选项,以保留页面刷新后,并试图与Jinga2这样做,虽然我觉得应该工作是行不通的。有一个选择选项保持选中POST后使用Flask
<div class="col-sm-4 col-lg-4 col-md-4">
<select class="form-control" id="myselect" name="thing" required>
<option value="" {% if thing=='' %} selected {% endif %} ></option>
<option value = "Foo" name ="Foo" id="Foo" {% if thing =="Foo" %} selected {% endif %} >Foo</option>
<option value = "Bar" name ="Bar" id="Bar" {% if thing =='Bar' %} selected {% endif %}>Bar</option>
</select>
</div>
可变能量填充并通过Python传递的地方。仔细研究之后,我觉得这是Flask的工作方式/语法,尽管显然不是。任何援助将不胜感激!
编辑: 的Python /瓶
@app,route('/things', methods=['POST']
def things()
if len(facts['thing']) > 11:
energy = [facts['thing'][0:8],facts['thing'][9:]]
else:
energy = [facts['things']]
....
return render_template('thing.html, thing=thing)
你可以发布一个你的服务器端流程代码的例子。当你说“刷新”时,我认为这意味着用户只是刷新页面,应该发送一个GET请求。所以这不会通过表单发布任何信息,所以我不知道如何保存变量。 –
我比在POST发生时使用“刷新”这个词意味着错误。我用我的Python/Flask编辑了这个问题,以及我如何存储和传递该变量。 – MVS