首页 > 解决方案 > for提交后重定向到首页

问题描述

尝试在提交表单后将我的网络应用程序重定向到主页,但它只是在地址栏中提供表单的查询。例如 /form?Name=input&Location=input

脚本.py

@app.route("/")
def home():
    return render_template("index.html")


@app.route("/form", methods=["POST", "GET"])
def form():
    if request.method == "GET":
        return render_template("form.html")
    else:

        return redirect(url_for("home"))

表单.html

    <!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>
<form >
    <input type="text" name="Name">
    <input type="text" name="Location">
    <input type="submit" value="submit">
</form>
</body>
</html>

标签: pythonflask

解决方案


推荐阅读