I know we can use HttpResponseInstance['headername'] = 'headervalue'
to add header to http response. But in this way, I have to rewrite all the generic view I am using, which makes much more work.
Is there a convenient way to add header to responses, like a callback for responses, or a url decorator?
You can write a middleware class and implement the method process_response
.
You should use a middleware class. Check out this thread.
Django 1.10 and above __init__
and __call__
should be implement. process_response
is deprecated.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With