ajax - Unable to add custom header to response -
i unable add custom header response returned render():
response = render(request, 'my_template.html', {'ctx1': 1, 'ctx2': 2}) response['my-custom-header'] = 'abc12345' return response
this response ajax request initiated using jquery's $.get()
. on chrome, response has template rendered properly, not have custom header. if print response
object before returning, see has custom header.
i thought issue because of this answer, added django middleware add header responses:
class customheadermiddleware(): def process_response(self, request, response): response['access-control-expose-headers'] = 'my-custom-header' return response
all responses have header access-control-expose-headers: my-custom-header
, still see issue.
my request local; i'm using django development web server.
if send non-ajax request, whatever custom header add in django visible in response on chrome. issue seems limited ajax requests.
i using django 1.11.4 , python2.
[edit]
if capture response in wireshark, see not have my-custom-header
. furthermore, if add custom header response dictionary in above middleware, header shows in wireshark , visible in chrome. seems django issue responses ajax requests.
this issue unrelated ajax. calling view using this template tag. custom response headers lost because of line 32 in code.
Comments
Post a Comment