tengke 发表于 2023-5-19 11:45:45

diango验证密码时候 无论是否正确都正常添加

class a_user(forms.ModelForm):
    passwords = forms.CharField(
      label="确认密码",
      widget=forms.PasswordInput
    )
    class Meta:
      model = models.admin
      fields = ["username","password","passwords"]
      widgets = {"password":forms.PasswordInput}
    def yz(self):
      pwd = self.cleaned_data.get("password")
      pwds = self.cleaned_data.get("passwords")
      if pwds != pwd:
            raise ValidationError("密码不一致")
      return pwds
def adminuseradd(request):
    if request.method == "GET":
      form = a_user()
      return render(request, "adminuseradd.html", {"form": form})
    form = a_user(data=request.POST)
    if form.is_valid():
      form.save()
      return redirect('/adminview')
    else:
      return render(request, "adminuseradd.html", {"form": form})


数据没有报错 大佬麻烦看看

python小小白哟 发表于 2023-5-19 11:45:46

楼主说的是Django
页: [1]
查看完整版本: diango验证密码时候 无论是否正确都正常添加