Python django.core.validators 模块,validate_email() 实例源码

我们从Python开源项目中,提取了以下2个代码示例,用于说明如何使用django.core.validators.validate_email()

项目:intel-manager-for-lustre    作者:intel-hpdd    | 项目源码 | 文件源码
def _user_account_prompt(self):
        log.info("An administrative user account will now be created using the " +
                 "credentials which you provide.")

        valid_username = False
        while not valid_username:
            username = self.get_input(msg="Username", empty_allowed=False)
            if username.find(" ") > -1:
                print "Username cannot contain spaces"
                continue
            valid_username = True

        password = self.get_pass(msg="Password", empty_allowed=False, confirm_msg="Confirm password")

        valid_email = False
        while not valid_email:
            email = self.get_input(msg="Email")
            if email and not self.validate_email(email):
                print "Email is not valid"
                continue
            valid_email = True

        return username, email, password
项目:intel-manager-for-lustre    作者:intel-hpdd    | 项目源码 | 文件源码
def validate_email(email):
        try:
            validate_email(email)
        except ValidationError:
            return False
        return True