开发者

Problem understanding a django form

开发者 https://www.devze.com 2023-02-16 16:13 出处:网络
class UserField(forms.EmailField): def clean(self, value): super(UserField, self).clean(value) try: User.objects.get(username=value)
class UserField(forms.EmailField):
def clean(self, value):
    super(UserField, self).clean(value)
    try:
        User.objects.get(username=value)
        raise forms.ValidationError("There is an exist开发者_运维问答ing account associated with this email.")
    except User.DoesNotExist:
        return value

the try except method is straightforward. However, I am having a hard time figuring out the

super(UserField, self).clean(value)


super(UserField, self).clean(value) is calling the ancestor method : forms.EmailField.clean(value) to check that the email is well formed.

0

精彩评论

暂无评论...
验证码 换一张
取 消