Advertisement
meoooh

Untitled

Dec 25th, 2012
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.23 KB | None | 0 0
  1. class RegistrationForm(forms.Form):
  2.     username = forms.CharField(label='사용자 이름', max_length=30)
  3.     email = forms.EmailField(label='전자우편')
  4.     password1 = forms.CharField(
  5.             label='비밀번호',
  6.             widget=forms.PasswordInput()
  7.             )  
  8.     password2 = forms.CharField(
  9.             label='비밀번호(확인용)',
  10.             widget=forms.PasswordInput()
  11.             )  
  12.  
  13.     def clean_password1(self):
  14.         if 'password1' in self.cleaned_data:
  15.             password1 = self.cleaned_data['password1']
  16.             password2 = self.cleaned_data['password2']
  17.             if password1 == password2:
  18.                 return password1
  19.         raise forms.ValidationError('비밀번호가 일치하지 않습니다.')
  20.  
  21.     def clean_username(self):
  22.         username = self.cleaned_data['username']
  23.         if not re.search(r'^\w+$', username):
  24.             raise forms.ValidationError(
  25.                     '사용자 이름은 알파벳, 숫자, 밑줄(_)만 가능합니다.')
  26.         try:
  27.             User.objects.get(username=username)
  28.         except ObjectDoesNotExist:
  29.             return username
  30.         raise forms.ValidationError('이미 사용 중인 사용자 이름입니다.')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement