I have a quick question,
In the admin panel, you can set the user's email as unique via:
User._meta.get_field('email')._unique = True
And I was wondering if you could also make it required like the above snippet, enforcing it through the database if so, how do I do that?
I am not sure if you are asking specifically for the admin login, but assuming you are ok logging in with the regular django-allauth flow, all you need to do is add the following settings (settings.py):
ACCOUNT_USER_MODEL_EMAIL_FIELD= 'email'
ACCOUNT_UNIQUE_EMAIL = True
ACCOUNT_USERNAME_REQUIRED = True
ACCOUNT_EMAIL_REQUIRED = True
If you want to switch to using the email itself for logging in (in which case, this will also make it required, and work on the admin login as well, add also
ACCOUNT_AUTHENTICATION_METHOD = 'email'
Hope this helps
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.