简易flask框架入门之服务器返回客户端的响应对象并且手动创建response对象

from flask import Flask,make_response
app = Flask(__name__)
@app.route('/')
def hello_world():
# 一. 直接返回
# 1. 返回, 响应体
#return "hello world"
# 2. 返回, 响应体 + 状态码
return "hello world","666bigererror"
#
# 3. 返回响应体 + 状态码 + 响应头
return "helloworld",666,{"Content-Type":"application/json"}
# 二手动创建response对象
response = make_response("helloworld")
response.status = "888 bigererror"
response.headers["Content-Type"] = "application/json"
response.headers["name"] = "banzhang"
return response
if __name__ == '__main__':
【简易flask框架入门之服务器返回客户端的响应对象并且手动创建response对象】app.run(debug=True)

    推荐阅读