为什么当我停用用户在Django管理网站在我的类在后方法
如果需求用户不是None,需求是否首先返回负数?
也许如果用户否定真Django不看他在用户表?
class LoginView(View):
template_name = 'login.html'
def get(self, request):
form = LoginForm()
return render(request, self.template_name, locals())
def post(self, request):
form = LoginForm(request.POST)
if form.is_valid():
username = form.cleaned_data.get('username')
password = form.cleaned_data.get('password')
user = authenticate(username=username, password=password)
if user is not None:
if user.is_active:
login(request, user)
return redirect('home')
else:
alert = messages.error(request, 'Twoje konto zostało zablokowane!')
return render(request, self.template_name, locals())
else:
alert = messages.error(request, 'Błędna nazwa użytkownika!')
return render(request, self.template_name, locals())
1条答案
按热度按时间mnemlml81#
在
authenticate
函数中,django在settings.py
中的AUTHENTICATION_BACKENDS
上调用authenticate
。ModelBackend
是Django提供的一个默认的身份验证后端,如果你正在使用它,它会检查用户是否处于活动状态。