I am not sure it's about django, rather javascript and browser.
my view:
def set_lang(request, lang):
request.session['lang'] = lang
# request.session.modified = True # optional, to be pretty sure
# request.session.save() # the same
return HttpResponse('ok')
in html, in js:
$.post('/set_lang', {'lang', 'EN'}); # it change session and works
location.reload()
somewhere while location.reload() the django session is "rollbacked" to previous state.
on chrome when I add own sleep method in js (1sec) before location.reload it works on firefox problem exists regardless.
I do not use cookies except session one. I tried cleanup browser cache, session, but without success. I can repeat this on different browser versions.
I have workaround but I am curious what happened.
when I remove from js location.reload()
, and then do POST/GET request will be handled ok with correct session.
F5 refresh
after set_lang also works always (session is changed correctly).
I compare http headers between location.reload
and F5 refresh
and they are the same.