· 7 years ago · Mar 02, 2019, 11:50 AM
1from django import forms
2
3class ContactForm(forms.Form):
4 fullname = forms.CharField(
5 widget=forms.TextInput(
6 attrs={
7 "class": "form-control",
8 "placeholder": "form_full_name"
9 }
10 )
11 )
12
13
14email = forms.EmailField(
15 widget=forms.EmailInput(
16 attrs={
17 "class": "form-control",
18 "placeholder": "your_email"
19 }
20 )
21)
22
23
24content = forms.CharField(
25 widget=forms.Textarea(
26 attrs={
27 'class': 'from-control',
28 "placeholder": "Your message"
29 }
30 )
31)
32
33def clean_email(self):
34 email = self.cleaned_data.get("email")
35 if not "gmail.com" in email:
36 raise forms.ValidationError("Email has to gmail.com")
37 return email
38
39#widget=forms.PasswordInput\\for heddin password
40class LoginForm(forms.Form):
41 username = forms.CharField()
42 password = forms.CharField(widget=forms.PasswordInput)
43
44
45class RegisterForm(forms.Form):
46 username = forms.CharField()
47 email = forms.EmailField(
48 password = forms.CharField(widget=forms.PasswordInput)
49 password2 = forms.CharField(label='Confirm password',widget=forms.PasswordInput)