小编MVS*_*MVS的帖子

使用 Flask POST 后,选择选项保持选中状态

我正在尝试获取一个选择选项,该选项在使用 Flask 刷新页面后被选中。我曾尝试使用 Jinga2 这样做,但它不起作用:

<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>
Run Code Online (Sandbox Code Playgroud)

energy使用 Python 填充和传递变量的位置。在研究了这个之后,我觉得这是在 Flask 中进行这项工作的方式,尽管显然不是。任何援助将不胜感激!

@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=energy)
Run Code Online (Sandbox Code Playgroud)

html python select jinja2 flask

2
推荐指数
1
解决办法
4985
查看次数

标签 统计

flask ×1

html ×1

jinja2 ×1

python ×1

select ×1