带有HTTP响应头的render_to_response

Int*_*tra 10 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))
Run Code Online (Sandbox Code Playgroud)

Yuj*_*ita 16

直接在响应对象上设置标头.

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

response = render_to_response(...)
response['Cache-Control'] = 'no-cache'
return response
Run Code Online (Sandbox Code Playgroud)