使用ajax完成python flask前端与后台数据的交互

python端:

from flask import Flask, render_template
import json
import os

app = Flask(__name__)

testInfo = {}


@app.route('/test_post/nn', methods=['GET', 'POST'])  # 路由
def test_post():
    testInfo['name'] = 'xiaoliao'
    testInfo['age'] = '28'
    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()

JS端:



 

    
    
    
    echarts

 

    

数据展示:

参考链接:

https://www.cnblogs.com/showersun/p/3745355.html

https://blog.csdn.net/we1583004we/article/details/81512893

http://www.w3school.com.cn/jquery/ajax_post.asp

你可能感兴趣的:(flask,jQuery)