1

我阅读了“如何使用会话”,添加django.contrib.sessions.middleware.SessionMiddlewareMIDDLEWARE_CLASSESdjango.contrib.sessionsINSTALLED_APPSsettings.py并在我看来尝试了以下操作:

if not request.session.get('confirmed_disclaimer', False):
    if request.method == "POST":
        form = DisclaimerForm(data=request.POST)
        if form.is_valid():
            request.session['confirmed_disclaimer'] = True
            return HttpResponseRedirect('.')
    else:
        form = DisclaimerForm()
else:
    if request.method == "POST":
        form = AuthenticationForm(data=request.POST)
        if form.is_valid():
            auth_login(request, form.get_user())
            return HttpResponseRedirect('.')
    else:
        form = AuthenticationForm(request)
return render_to_response('login.html', {'form': form, },
                          context_instance=RequestContext(request))

这应该首先显示免责声明表单,然后显示登录表单,如果尚未确认一次(会话)。但是我在之后失去了会议HttpResponseRedirect

我用错了吗?

谢谢任何建议!

编辑

有一个

...
logout(request)
return login(request)

在 Mixin 中。这每次都会创建一个新会话,很抱歉,感谢您尝试帮助@DrTyrsa!

4

0 回答 0