首页 > 其他分享 >原生django怎么给响应头添加信息

原生django怎么给响应头添加信息

时间:2023-02-28 15:45:34浏览次数:37  
标签:原生 res 视图 django 响应 添加

原生django怎么给响应头添加信息

直接在HttpResponse响应对象中添加键值对就行

视图层
——————————————————————
def test_func(request):
   # logger.info('info级别的日志~')
    print('我被执行了')
    res = HttpResponse('嘻嘻')
    res['ikun'] = 'wooooo~'
    return res

同理,JsonResponse也是这样

视图层
——————————————————————
def test_func(request):
res = JsonResponse({'name':'jack'})
res['ikun'] = 'wooooo~'
return res

标签:原生,res,视图,django,响应,添加
From: https://www.cnblogs.com/wznn125ml/p/17164491.html

相关文章