使用Django注册验证自定义电子邮件域 [英] Validate Custom Email Domains with Django-Registration

查看:246
本文介绍了使用Django注册验证自定义电子邮件域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到一个版本的JQuery EDU验证 here 但我很想使用 django-registraion 来检查一个完整的域 @ someschool.edu @ alumni.someschool.edu



任何想法?感谢您的帮助。

解决方案

您可以在forms.py中创建自己的表单,您已经有一些示例: p>


  • 注册服务条款

  • 使用唯一邮件注册

  • 没有免费电子邮件的注册



在你的情况下添加:

  class RegistrationFormEduMail(RegistrationForm):

good_domains = ['edu']

def clean_email(self):

email_domain = self.cleaned_data ['email']。split('。')[ - 1]
如果email_domain不在self.good_domains中:
raise forms.ValidationError(_(使用非edu电子邮件地址注册被禁止,请提供不同的电子邮件地址。))
return self.cleaned_data ['email']

然后进入注册/后端/默认/ init .py并导入您的表单,更改表单r的名称由get_form_class()方法执行到您的表单的名称(这里:RegistrationFormEduMail)


I saw a version of JQuery EDU validation here but I'd love to use django-registraion to check a full domain @someschool.edu or @alumni.someschool.edu

Any ideas? Thanks for your help.

解决方案

You can create your own form in forms.py, you already have some example for :

  • registration with term of service
  • registration with unique mail
  • registration without freeemail

In your case add :

class RegistrationFormEduMail(RegistrationForm):

    good_domains = ['edu']

    def clean_email(self):

        email_domain = self.cleaned_data['email'].split('.')[-1]
        if email_domain not in self.good_domains:
            raise forms.ValidationError(_("Registration using non edu email addresses is prohibited. Please supply a different email address."))
        return self.cleaned_data['email']

Then go in registration/backends/default/init.py and import your form, change the name of the form returned by get_form_class() method to the name of your form (here: RegistrationFormEduMail)

这篇关于使用Django注册验证自定义电子邮件域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆