django.contrib.auth
Django的用户验证框架,可以快速实现用户信息验证、登录、登出等用户操作
from django.contrib.auth import authenticate, login, logout
# 例:登录
if request.method == "POST":
login_form = LoginForm(request.POST)
if login_form.is_valid():
cd = login_form.cleaned_data
user = authenticate(username=cd['username'], password=cd['password']) # django自带的用户信息验证功能
if user and user.is_active:
login(request, user) # 生成sesseionid发送给客户端,django自带的用户登录功能
return redirect(reverse('account_django:home'))
else:
message = '用户名或密码错误!'
return render(request, 'account_django/login_django_bootstrap3.html',
{"form": login_form, "message": message})
else:
return HttpResponse("Invalid login")