forms.py 1.5 KB

123456789101112131415161718192021222324252627282930
  1. from django import forms
  2. from django.contrib.auth.forms import UserCreationForm,AuthenticationForm,UsernameField
  3. from django.contrib.auth.models import User
  4. from django.utils.translation import gettext,gettext_lazy as _
  5. from .models import Post
  6. class SignUpForm(UserCreationForm):
  7. password1=forms.CharField(label='Password',widget=forms.PasswordInput(attrs={'class':'form-control'}))
  8. password2=forms.CharField(label='Confirm Password',widget=forms.PasswordInput(attrs={'class':'form-control'}))
  9. class Meta:
  10. model=User
  11. fields = ['username','first_name','last_name','email']
  12. labels = {'first_name':'First Name','last_name':'Last Name','email':'Email'}
  13. widgets = {'username':forms.TextInput(attrs={'class':'form-control'}),
  14. 'first_name':forms.TextInput(attrs={'class':'form-control'}),
  15. 'last_name':forms.TextInput(attrs={'class':'form-control'}),
  16. 'email':forms.EmailInput(attrs={'class':'form-control'}),
  17. }
  18. class LoginForm(AuthenticationForm):
  19. username = UsernameField(widget=forms.TextInput(attrs={'autofocus':True,'class':'form-control'}))
  20. password = forms.CharField(label=_("Password"),strip=False,widget=forms.PasswordInput(attrs={'class':'form-control'}))
  21. class PostForm(forms.ModelForm):
  22. class Meta:
  23. model = Post
  24. fields = ['title', 'desc']
  25. labels = {'title':'Title', 'desc':'Description'}
  26. widgets = {'title':forms.TextInput(attrs={'class':'form-control'}),
  27. 'desc':forms.Textarea(attrs={'class':'form-control'}), }