python代碼:
# -*- coding: utf-8 -*-
from flask import Flask,jsonify,render_template,request
import json
app = Flask(__name__)#實例化app對象
testInfo = {}
num=10
@app.route('/test_post/nn',methods=['GET','POST'])#路由
def test_post():
global num
'''receive data'''
recv_data = request.get_data()
if recv_data:
print recv_data
json_re = json.loads(recv_data)
print json_re['email']
print json_re['phone']
else:
print("receive data is empty")
'''send data'''
num = num + 1
testInfo['name'] = 'xiaoming'
testInfo['age'] = num
return json.dumps(testInfo)
@app.route('/')
def hello_world():
return 'Hello World!'
@app.route('/index')
def index():
return render_template('index.html')
if __name__ == '__main__':
app.run(host='0.0.0.0',#任何ip都可以訪問
port=7777,#端口
debug=True
)
前端代碼:
echarts
數(shù)據(jù)展示:
以上這篇python實現(xiàn)通過flask和前端進行數(shù)據(jù)收發(fā)就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061
微信掃一掃加我為好友
QQ號聯(lián)系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元

