Python社区  »  Django

如何检查django register.html中是否填写了所有字段?

Gnanavel pandian • 1 月前 • 94 次点击  

 #views.py
   def register(request):
    if request.method == "POST":
        email=request.POST['email']
        User_name=request.POST['User_name']
        Password1=request.POST['Password1']
        Password2=request.POST['Password2']
        if Password1 == Password2:
            if User.objects.filter(username=User_name).exists():
                messages.info(request,'Username Taken')
                return redirect('register')
            elif User.objects.filter(email=email).exists():
                messages.info(request,'Email Taken')
                return redirect('register')
            else:
                user = 
                              User.objects.create_user(username=User_name,
                                        password=Password1,email=email)
                user.save();
                return redirect('/')
        else:
            messages.info(request,'Password Not Matching')
    else:
        return render(request,'register.html')
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/54866
 
94 次点击  
分享到微博