How to add an HTTP header to all Django responses

Viewed 24830

I'd like to add a few headers to all responses that my Django website returns. Is there a way to do this (besides adding a wrapper to the render function)?

2 Answers

When returning JsonResponse.

from django.http import JsonResponse

data = {'key','value'} # some data

response = JsonResponse(data,status=200)

response['Retry-after'] = 345 # seconds 
response['custom-header'] = 'some value'

return response 
Related