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))
A response header is an HTTP header that can be used in an HTTP response and that doesn't relate to the content of the message. Response headers, like Age , Location or Server are used to give a more detailed context of the response.
Select the web site where you want to add the custom HTTP response header. In the web site pane, double-click HTTP Response Headers in the IIS section. In the actions pane, select Add. In the Name box, type the custom HTTP header name.
Can I read response headers in JavaScript? While you can't ready any headers of HTML response in JS, you can read Server-Timing header, and you can pass arbitrary key-value data through it.
An HTTP response header is a component of a network packet that is sent by a Web server to a Web browser or client machine in response to an HTTP request. It is used in Web communications to deliver webpage and other Web-based data from the server to the requesting end-user browsers.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With