To add login with email with Python Django, we can add an EmaolFoeld
with unique
set to True
.
For instance, we write
class MyUser(AbstractUser):
USERNAME_FIELD = 'email'
email = models.EmailField(_('email address'), unique=True)
REQUIRED_FIELDS = []
to create the email
EmailField
that has unique
set to True
to make all the values of it unique.
And then we set USERNAME_FIELD
to 'email'
to make the username field the email
field we just created.
Then we can use authenticate(email=email, password=password)
to authenticate.