Django session doesn't work in Firefox

倾然丶 夕夏残阳落幕 提交于 2020-01-11 09:25:35

问题


I have a search view that saves some data in a session for another view:

def search(request):
    ...
    if request.method == 'POST':
        form = SearchForm(request.POST)
        if form.is_valid():
            cd = form.cleaned_data
            melk=data(cd)
            request.session['data'] = melk
            request.session['form'] = form
            return redirect('/result/')
    ...

def result(request):
    ...
    melk_list = request.session['data']
    form = request.session['form']
    ...

When I use Chrome, everything is good. But when I use Firefox, it works fine the first time, but after that each search keeps returning my first result! It seems request.session doesn't change after the first time. I tried to delete the session with del request.session['data'], but that didn't work.

My session backend is a database, but Firefox makes a session cookie.


回答1:


Try

request.session.modified = True


来源:https://stackoverflow.com/questions/13626783/django-session-doesnt-work-in-firefox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!