python实现通过flask和前端进行数据收发
python代码:
#-*-coding:utf-8-*- fromflaskimportFlask,jsonify,render_template,request importjson app=Flask(__name__)#实例化app对象 testInfo={} num=10 @app.route('/test_post/nn',methods=['GET','POST'])#路由 deftest_post(): globalnum '''receivedata''' recv_data=request.get_data() ifrecv_data: printrecv_data json_re=json.loads(recv_data) printjson_re['email'] printjson_re['phone'] else: print("receivedataisempty") '''senddata''' num=num+1 testInfo['name']='xiaoming' testInfo['age']=num returnjson.dumps(testInfo) @app.route('/') defhello_world(): return'HelloWorld!' @app.route('/index') defindex(): returnrender_template('index.html') if__name__=='__main__': app.run(host='0.0.0.0',#任何ip都可以访问 port=7777,#端口 debug=True )
前端代码:
echarts html, body{ width:100%; height:100%; } body{ margin:0px; padding:0px } div{ float:left; } #container{ width:50%; height:100%; } #info{ padding:10px20px; }