Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

render_to_response with HTTP response headers

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))
like image 867
Intra Avatar asked Apr 12 '12 19:04

Intra


People also ask

Do HTTP responses have headers?

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.

How do I add HTTP response header?

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 JavaScript read response headers?

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.

What HTTP response headers do?

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.


1 Answers

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
like image 197
Yuji 'Tomita' Tomita Avatar answered Oct 04 '22 06:10

Yuji 'Tomita' Tomita