訪問表單域

你可以通過 request.form 屬性訪問 Flask 中通過 POSTPUT 請求提交的表單資料。

from flask import Flask, request

app = Flask(import_name=__name__)

@app.route("/echo", methods=["POST"])
def echo():

    name = request.form.get("name", "")
    age = request.form.get("age", "")

    response = "Hey there {}! You said you are {} years old.".format(name, age)

    return response

app.run()