登录注册

#注册
def
register_acc(request): if request.method == 'POST': userName = request.POST.get('userName') passWord = request.POST.get('passWord') name = request.POST.get('myname') if User.objects.filter(username = userName): erro = '用户名已存在' return render(request,'register.html',context={'erro':erro}) else: user = User.objects.create_user(username=userName,password=passWord) user.save() userProfile = models.UserProfile() userProfile.user = user userProfile.userName = name userProfile.save() login(request,user) return render(request,'index.html') return render(request,'register.html')
#登录
def login_acc(request):
    if request.method == 'POST':
        userName = request.POST.get('userName')
        passWord = request.POST.get('passWord')
        user = authenticate(username=userName,password=passWord)
        print('user:',user)
        if user is not None:
            login(request,user)
            return render(request,'index.html')
        else:
            erro = '用户名或密码错误'
            return render(request,'login.html',context={'erro':erro})
    return render(request,'login.html')

 



 

posted on 2017-10-11 13:41  run_qin  阅读(228)  评论(0编辑  收藏  举报

导航