from flask import Flask,request
app=Flask(__name__)
@app.route("/lele",methods=["GET","POST"])
def lele():
""" You can test this in postman by selecting `form-data` in the
`Body` and giving the `name` as key and value michael (let's say)."""
user=request.form['name']
return str(user) # this is a POST request
# return "lele" # this is a GET request
if __name__=="__main__":
app.run(debug=True)
1条答案
按热度按时间7lrncoxx1#
当你运行
curl http://127.0.0.1:5000/lele
时,函数应该返回lele
,这就是返回的内容。如果你想看到lele
作为输出,那么它是一个GET请求。如果你想看到michael
作为输出,那么它是一个POST请求。