How do I add a response header to a Django response? I have:
response = HttpResponse()
response['Cache-Control'] = 'no-cache'
return render(request, "template.html", {})
# Alternately using render_to_response
# return render_to_response("template.html", {})
Assign the result of
render
to a variable, set the header, then return the response.Most of the time, it is simpler to user
render
thanrender_to_response
. However, if you are usingrender_to_response
, the same approach will work: