简体   繁体   中英

Django custom authentication with email as username

So I am a bit stuck right now.I know about django user model and what means to extend it..kinda. The thing is that I don't know how to get started... I have a student model where name, surname and student ID are entered in by the admin. Fields of email, phone and photo, are readonly. I want that a student can make an account, where he can enter all those fields himself, but name, surname and student ID need to match with those from database, otherwise he cannot make account. What is a good approach ?

 class Student(models.Model): name = models.CharField(max_length=50) surname = models.CharField(max_length=50) student_ID = models.CharField(unique=True, max_length=14, validators=[RegexValidator(regex='^.{14}$', message='The ID needs to be 14 characters long.')]) photo = models.ImageField(upload_to='students_images') email = models.EmailField() phone = models.CharField(max_length=15, ) def __str__(self): return self.name + self.surname 

This is how I started.

如果您希望使用用户电子邮件而不是常规用户名进行身份验证,则需要使用从AbstractBaseUser继承的自定义用户模型。您可以在此处找到有关如何执行此操作的详细信息

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM