如何在form.py中创建一个必填字段的电子邮件字段?

时间:2018-05-29 17:09:28

标签: python django content-management-system

我一直在尝试几种方法,但似乎无法使其发挥作用。

以下是我的代码:

sparse_softmax_cross_entropy_with_logits

有谁知道为什么required = True不能使它成为必填字段?

1 个答案:

答案 0 :(得分:0)

@WillemVanOnsem在对您的问题的评论中说了什么,我将在此处进行扩展以使其更清晰:您应该调用super().clean_email()以确保该字段的所有默认验证都已运行。

def clean_email(self):
    email = super().clean_email()

    if email is not None:
        # check if account with email exists
        if User.objects.filter(email=email).exists():
            raise ValidationError('Email address already exists.')

    return email
相关问题