Flask 自带jsonify 直接返回json一条龙

# coding=utf-8
from flask import Flask,jsonify
import json


app = Flask(__name__)






@app.route("/index")
def index():
    data = {
        "name": "zhangsan",
        "age": 18
    }


    #json_str = json.dumps(data)
    #return json_str,200,{"Content-Type":"application/json"}


    #帮助转换为json字符串, 并且设置响应头Content-Type: application/json
    return jsonify(data)


@app.route("/hello")
def hello():
    return jsonify(name="wancheng",subject="python")






if __name__ == '__main__':
    app.run(host="192.168.65.34",port=5000,debug=True)
阅读更多
换一批

没有更多推荐了,返回首页