flask - 如何使用 GET/POST 将 GET 发送到烧瓶
问题描述
在模板文件夹中我有 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 请求和任何可能的解决方案?
解决方案
我不知道你是不是搞砸了,但我知道你不能在没有帮助的情况下测试发帖,它是不可见的。您需要像 Postman 或服务器这样的应用程序。也许就是这样。
推荐阅读
- mysql - 如何基于 2 个 JSON 对象列内部连接两个表?
- typescript - 构造函数接口:没有匹配构造函数的类仍然是可赋值的
- flutter - Dart:在 Flutter 应用程序中最小化对 Firebase 的访问
- css-grid - 为什么 CSS Grid-Area 结束坐标偏移?
- google-cloud-firestore - 按包含“.”的映射键查询
- wso2 - WSO 7.0 Micro Integrator 多数据服务
- asp.net-core - ASP.NET Core MVC:模型绑定和复杂类型
- php - 如何获取表单选择值以显示正在插入的表中的两件事?
- javascript - Webpack + Typscript 库导入在 React 项目中未定义
- google-app-engine - 用于从应用程序引擎 flex 检查任务队列长度的 API?