HttpResponse
方法一:
return HttpResponse('ok',headers={'xxx':'xxx'})
方法二:
obj = HttpResponse('ok') obj['yyy'] = 'yyy' # 像字典一样放入,最终会放在http的响应头中 return obj
redirect
无法直接传headers=
传入数据方法:
obj = redirect('url') obj['xxx'] = 'xxx' return obj
render
同样无法使用headers
传入数据方法:
obj = render(request, 'url') obj['xxx'] = 'xxx' eturn obj
JsonResponse
与HttpResponse
相同
方法一:
return JsonResponse({'name':'kevin'},headers={'xxx': 'ssss'})
方法二:
obj=JsonResponse({'name':'kevin'}) obj['yyy']='yyy' return obj
标签:四件套,return,xxx,yyy,Django,headers,HttpResponse,obj,放入 From: https://www.cnblogs.com/wellplayed/p/17867457.html