首页 > 解决方案 > 如何使用 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 请求和任何可能的解决方案?

标签: flaskhttp-postjinja2get-requestpython-requests-html

解决方案


我不知道你是不是搞砸了,但我知道你不能在没有帮助的情况下测试发帖,它是不可见的。您需要像 Postman 或服务器这样的应用程序。也许就是这样。


推荐阅读