Django TypeError at /login/ 'bool' object is not callable
代码:
def login(request): if request.POST: username = request.POST.get('username') password = request.POST.get('password') user = auth.authenticate(username=username, password=password) if user is not None and user.is_active(): auth.login(request, user) request.session['user'] = username response = HttpResponseRedirect('/home/') return response else: return render(request, 'login.html', {'error': 'username or password error'}) return render(request, 'login.html')
运行结果:
问题原因:
is_active 非方法,而是一个属性,通常是指对象是否激活、启用、可用、正常状态。将代码中is_active()中的括号去掉