- 示例腳本
from flask import Flask
# 獲取一個實例對象
app = Flask(__name__)
# 1、注冊
@app.route('/reg', methods=['get'])
def reg():
return {
'code': 200,
'msg': 'reg ok!'
}
# 2、登錄
@app.route('/login', methods=['get'])
def login():
return 'login ok!'
if __name__ == '__main__':
app.run()
- 運行腳本
- 在瀏覽器上校驗
在瀏覽器地址欄輸入URL和定義的路徑,回車請求,校驗響應數(shù)據(jù)是否正確。 - 也可使用Python-requests庫請求回調測試
import requests
url = 'http://127.0.0.1:5000'
r = requests.get(url + '/reg')
print(r.status_code)
print(r.json())
- 運行腳本
文章來源地址http://www.zghlxwxcb.cn/news/detail-630950.html
文章來源:http://www.zghlxwxcb.cn/news/detail-630950.html
到了這里,關于使用Python + Flask搭建web服務的文章就介紹完了。如果您還想了解更多內容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!