。
的形式将结果张贴在template.html中。index.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>
template.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请求和任何可能的解决方案吗?