djangohttp-headersrender-to-response

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))

Solution

  • 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