重定向到仪表板之前先进行身份验证

时间:2019-04-21 19:33:46

标签: django

我在显示视图之前放置了身份验证,但是在运行它时会出现此错误 TypeError:“ bool”对象不可调用

user.is_autheticated()在Django 2.1.5中不起作用

def Login_View(request):
    if request.method == "POST":
        username = request.POST['username']
        password = request.POST['pwd']
        user = authenticate(username=username, password=password)
        if user is not None:
            if user.is_active:
                login(request, user)
                data_user = User.objects.get(username=request.user)
                request.session['username'] = username
                return render(request,'dashboard_app/index.html',{'data_user':data_user.username})
            else:
                return render(request, 'login_app/index.html', {'error_message': 'Your account has been disabled'})
        else:
            return render(request, 'login_app/index.html', {'error_message': 'Invalid login'})
    return render(request, 'login_app/index.html')

def Dashboard_View(request):
    if request.user.is_authenticated():
        if request.session.has_key('username'):
            name=request.session['username']
            return render(request, "dashboard_app/index.html",{'name':name})
        else:
            request.session['username'] = User.username
    else:
        return render(request, "Login_app/index.html")

我要在重定向页面之前进行身份验证

0 个答案:

没有答案