這篇文章主要介紹python實(shí)現(xiàn)通過(guò)flask和前端進(jìn)行數(shù)據(jù)收發(fā)的方法,文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!
python代碼:
# -*- coding: utf-8 -*- from flask import Flask,jsonify,render_template,request import json app = Flask(__name__)#實(shí)例化app對(duì)象 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都可以訪問(wèn) port=7777,#端口 debug=True )
前端代碼:
echarts 數(shù)據(jù)展示:
以上是“python實(shí)現(xiàn)通過(guò)flask和前端進(jìn)行數(shù)據(jù)收發(fā)的方法”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對(duì)大家有幫助,更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)成都網(wǎng)站設(shè)計(jì)公司行業(yè)資訊頻道!
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。