0
어떻게 '필요 = 거짓'필드의 방법을 clean_ 호출하지 않습니다?어떻게 '필요 = 거짓'분야에서 clean_ <fieldname> 메소드를 호출하지?
forms.py
from django import forms
class userRegistrationForm(forms.Form):
username = forms.CharField(
max_length=30,
)
password1 = forms.CharField(
widget=forms.PasswordInput(),
)
email = forms.EmailField( # If user fill this, django will call 'clean_email' method.
required=False, # But when user don't fill this, I don't want calling 'clean_email' method.
)
def clean_email(self):
if 'email' in self.cleaned_data:
try:
User.objects.get(email=self.cleaned_data['email'])
except ObjectDoesNotExist:
return self.cleaned_data['email']
else:
raise forms.ValidationError('Wrong Email!')
사용자는 '이메일'을 채울 수와 '이메일'필드를 입력 할 필요가 없습니다.
어떻게해야합니까?
오! 매우 감사합니다...! – chobo