在模板文件夹中我有 index.html 和 template.html 我正在尝试从 index.html 中的表单获取数据,处理数据并将结果发布到 template.html 为
.
索引.html:
<form method="POST">
<select class="browser-default custom-select" name="regions_brato">
<option selected>Open this select menu</option>
{% for each,key in new_dict.items() %}
<option value="{{each}}">{{each}}</option>
{% endfor %}
</select>
<select name="list_status">
{% for key in listStatus %}
<option value="{{key}}">{{key}}</option>
{% endfor %}
</select>
<input type="submit">
</form>
模板.html:
..
<body>
{% for each,key in res.items() %}
<p>{{each}}</p>
{% endfor %}
</body>
..
烧瓶:
@application.route('/', methods=['GET', 'POST'])
def form():
listStatus = ['en', 'fr', 'bg']
new_dict = {}
with open('fr.json') as json_file:
data = json.load(json_file)
for each in data:
new_dict.setdefault(each['admin'], []).append(each['city'])
if request.method == 'GET':
return render_template('index.html', listStatus=listStatus, default="en", new_dict=new_dict)
else:
return redirect(url_for('template'))
@application.route('/template')
def template():
region = request.form["regions_brato"]
lang = request.form["list_status"]
res = get_feel(region, lang, 30)
return render_template("template.html", res=res)
谁能指出我到底在哪里弄乱了 GET/POST 请求和任何可能的解决方案?