我知道如何返回JSON响应:
return Response({'example':'example'})
并且还知道如何返回文件响应:
response = HttpResponse(pdf, content_type='application/pdf')
response['Content-Disposition'] = 'attachment; filename="mypdf.pdf"'
return response
但是如果我想在一个响应中同时发送两个,我该如何[[正确这样做? Django documentation给出了设置其他标题字段的示例:
>>> response = HttpResponse()
>>> response['Age'] = 120
但是从我看到的一对answers来看,看起来好像是在标头中发送业务数据,这不是走的路。有更好的解决方案吗?
Content-Disposition
,有两个选项:attachment; key=value; filename="my.txt"
。