访问表单域

你可以通过 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()