带有HTTP响应头的render_to_response

时间:2012-04-12 19:35:29

标签: django http-headers render-to-response

如何在Django render_to_response中使用HTTP响应头

我想使用Cache-Control,但无法判断它是否正常工作。以下是正确的:

render_to_response(templatename, {'Cache-Control':'no-cache'},context_instance=RequestContext(httpreq))

1 个答案:

答案 0 :(得分:16)

直接在响应对象上设置标题。

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

response = render_to_response(...)
response['Cache-Control'] = 'no-cache'
return response