jsonify帮助转为json数据,并设置响应头,Content-Type为application/json
from flask import Flask,jsonify
import json
app = Flask(__name__)
@app.route("/index")
def index():
# json就是字符串
data = {
"name":"python",
"age":24
}
# jsonify帮助转为json数据,并设置响应头,Content-Type为application/json
return jsonify(data)
if __name__ == '__main__':
app.run(debug=True)
image.png
网友评论