render_to_response with HTTP response headers
-
31-05-2021 - |
Question
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))
Solution
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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow