from flask import Flask,make_response,json
app = Flask(name)
@app.route("/") def index(): response=make_response("hello") response.mimetype='text/plain' #text/html application/xml application/json return response @app.route("/data") def foo(): data={ 'name':'jack', 'gender':'male' } response=make_response(json.dumps(data)) response.mimetype='application/json' return response
或者:return jsonify({name:'Grey Li',gender:'male'})
或者:return jsonify({name:'Grey Li',gender:'male'}),500
if name == 'main': app.run( host='0.0.0.0', port=8888, debug=True )
response.set_cookie() key,value,max_age,expires,path,domain,httponly