10

How to use HTTP response headers with Django render_to_response

I want to use Cache-Control but can't tell if it is working. Is the following correct:

render_to_response(templatename, {'Cache-Control':'no-cache'},context_instance=RequestContext(httpreq))
Intra
  • 2,089
  • 3
  • 19
  • 23

1 Answers1

16

Set headers directly on the response object.

https://docs.djangoproject.com/en/dev/ref/request-response/#setting-headers

response = render_to_response(...)
response['Cache-Control'] = 'no-cache'
return response
Yuji 'Tomita' Tomita
  • 115,817
  • 29
  • 282
  • 245