form.py 798 B

12345678910111213141516171819202122232425262728293031
  1. from django import forms
  2. from django.contrib.auth.models import User
  3. from .models import Profile
  4. class UserLoginForm(forms.Form):
  5. username = forms.CharField()
  6. password = forms.CharField()
  7. token = forms.CharField()
  8. class UserRegisterForm(forms.ModelForm):
  9. password = forms.CharField()
  10. password2 = forms.CharField()
  11. class Meta:
  12. model = User
  13. fields = ('username', 'email')
  14. def clean_password2(self):
  15. data = self.cleaned_data
  16. if data.get('password') == data.get('password2'):
  17. return data.get('password')
  18. else:
  19. raise forms.ValidationError('密码输入不一致,请重新输入!')
  20. class ProfileForm(forms.ModelForm):
  21. class Meta:
  22. model = Profile
  23. fields = ('phone', 'avatar', 'bio')