python代碼
from flask import Flask, request, jsonify
app = Flask(__name__)
#用/data路徑路由
@app.route('/data')
def get_data():
## 以下一行是從URL中獲取參數(shù)的get方法
data = request.args.get('data')
return jsonify(
data = data,
info = "success !",
code = "200"
)
if __name__ == '__main__':
app.debug = True
app.run(host='192.111.111.111', port=5555)
# app.run()
get方法可以不需要任何前端代碼,直接運(yùn)行以上Python代碼,控制端會有以下輸出
* Serving Flask app 'flask_service'
* Debug mode: on
WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
* Running on http://127.0.0.1:5000
Press CTRL+C to quit
* Restarting with stat
* Debugger is active!
* Debugger PIN: 631-444-681
http://127.0.0.1:5000為我們的URL,因為我們做了/data的路由,所以在瀏覽器地址欄輸入http://127.0.0.1:5000/data?data=2013.9文章來源:http://www.zghlxwxcb.cn/news/detail-709459.html
頁面可以返回python文件中設(shè)定的json格式數(shù)據(jù):文章來源地址http://www.zghlxwxcb.cn/news/detail-709459.html
{
"code": "200",
"data": "2013.4.4",
"info": "success !"
}
到了這里,關(guān)于python實(shí)現(xiàn)Flask GET Demo的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!