如何在Django render_to_response中使用HTTP响应头
我想使用Cache-Control,但无法判断它是否正常工作。以下是正确的:
render_to_response(templatename, {'Cache-Control':'no-cache'},context_instance=RequestContext(httpreq))
答案 0 :(得分:16)
直接在响应对象上设置标题。
https://docs.djangoproject.com/en/dev/ref/request-response/#setting-headers
response = render_to_response(...)
response['Cache-Control'] = 'no-cache'
return response