Django modelform how to add a confirm password field?

前端 未结 4 695
没有蜡笔的小新
没有蜡笔的小新 2021-02-04 01:40

Here I need to add an extra confirmation password in my form.I used Django\'s modelform. I also need to validate both passwords. It must raise a validation error if

4条回答
  •  广开言路
    2021-02-04 02:06

    def clean(self):
        cleaned_data = super(UserAccountForm, self).clean()
        password = cleaned_data.get("password")
        confirm_password = cleaned_data.get("confirm_password")
    
        if password != confirm_password:
            self.add_error('confirm_password', "Password does not match")
    
        return cleaned_data
    

提交回复
热议问题