from flask import Flask,make_response
app = Flask(__name__)
@app.route('/')
def hello_world():
? ? # 一. 直接返回
? ? # 1. 返回, 響應體
? ? #? ? return "hello world"
? ? # 2. 返回, 響應體 + 狀態(tài)碼
? ? ? ? return "hello world","666bigererror"
? ? #
? ? # 3. 返回響應體 + 狀態(tài)碼 + 響應頭
? ? ? ? return "helloworld",666,{"Content-Type":"application/json"}
? ? # 二手動創(chuàng)建response對象
? ? response = make_response("helloworld")
? ? response.status = "888 bigererror"
? ? response.headers["Content-Type"] = "application/json"
? ? response.headers["name"] = "banzhang"
? ? return response
if __name__ == '__main__':
? ? app.run(debug=True)