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

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -