66
77class LoginForm (forms .Form ):
88 username = forms .CharField (
9- max_length = 28 ,
9+ max_length = 150 ,
1010 widget = forms .TextInput (
1111 attrs = {"placeholder" : "Username..." , "class" : "form-control rounded-4" }
1212 ),
13+ error_messages = {
14+ "required" : "Username is required!" ,
15+ 'max_length' : "Username is too lang, max length is 150 charecters."
16+ }
1317 )
1418 password = forms .CharField (
1519 max_length = 60 ,
1620 widget = forms .PasswordInput (
1721 attrs = {"placeholder" : "Password..." , "class" : "form-control rounded-4" }
1822 ),
23+ error_messages = {
24+ "required" : "Password is required!" ,
25+ "max_length" : "Password is to long, max length is 60 charecters."
26+ }
1927 )
2028
2129
2230class RegisterForm (forms .ModelForm ):
2331 password1 = forms .CharField (
32+ label = "Password" ,
2433 max_length = 28 ,
2534 widget = forms .PasswordInput (attrs = {"id" : "password" , "type" : "password" }),
35+
2636 )
2737 password2 = forms .CharField (
38+ label = "Password (Confirm)" ,
2839 max_length = 28 ,
2940 widget = forms .PasswordInput (attrs = {"id" : "password" , "type" : "password" }),
3041 )
@@ -39,7 +50,7 @@ def save(self, commit=True):
3950 user .set_password (password1 )
4051 user .save ()
4152 else :
42- raise ValidationError ("Password must be match" )
53+ return ValidationError ("Passwords must be match! " )
4354
4455 def __init__ (self , * args , ** kwargs ):
4556 super ().__init__ (* args , ** kwargs )
0 commit comments