idea:vscode
1.vscode安裝插件python,搜索後安裝
2.創建文件夾pythondemo
3.pythondemo下創建文件.py結尾,嘗試寫個helloworld
4.在pythondemo目錄下安裝插件flask(或者在python安裝目錄/scripts目錄下全局安裝):
5.編寫代碼,運行
from flask import Flask
app=Flask(__name__)
# 只接受get方法訪問
@app.route("/hello",methods=["GET"])
def hello():
return "hello world"
if __name__=="__main__":
app.run()
雙擊f5
6.postman調用接口
案例2:獲取請求體的header及
from flask import Flask, request
app=Flask(__name__)
# 只接受POST方法訪問
@app.route("/filediff",methods=["POST"])
def filediff():
print request.headers
print request.form
return "hello world"
if __name__=="__main__":
app.run()
具體類型有:
- request.form
- request.args
- request.querystring
- request.data
- request.json
- 具體可以通過:print dir(request)打印出來;或者通過 Visual Studio IntelliCode 插件代碼提示(商店搜索)