如何向 Django 响应添加响应标头?我有:
response = HttpResponse()
response['Cache-Control'] = 'no-cache'
return render(request, "template.html", {})
# Alternately using render_to_response
# return render_to_response("template.html", {})
如何向 Django 响应添加响应标头?我有:
response = HttpResponse()
response['Cache-Control'] = 'no-cache'
return render(request, "template.html", {})
# Alternately using render_to_response
# return render_to_response("template.html", {})
将结果分配render
给变量,设置标头,然后返回响应。
response = render(request, "template.html", {})
response['Cache-Control'] = 'no-cache'
return response
大多数时候,它对用户来说render
比render_to_response
. 但是,如果您正在使用render_to_response
,则相同的方法将起作用:
response = render_to_response("template.html", {})
response['Cache-Control'] = 'no-cache'
return response