Flask make_response(*args)

视图本质上是返回一个response对象(也可以直接创建Response对象),但是在return后不方便设置头信息等,所以还是先封装成response对象,再返回比较全面,如下:

def index():
    return render_template('index.html')

make_response可以设置返回的其他信息

def index():
    response = make_response(render_template('index.html'))
    response.headers['X-Parachutes'] = 'parachutes are cool'
    return response
参数描述
str通过字符串创建response对象
bytes通过字节创建response对象
dict通过字典撞见response对象
tuple(body, status, headers) (body, status) (body, headers)

在使用tuple时:
body可以是str,bytes或dict
status可以是str或者integer
headers可以是dict或[(key,value),(key,value)]
如果body是一个response对象,其status会覆盖headers的

参考:
https://flask.palletsprojects.com/en/1.1.x/api/#flask.make_response
https://www.cnblogs.com/zhuchunyu/p/10466509.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值