我刚刚将django-allauth添加到我们的项目中。启动该应用程序时,我没有运行任何种子,但是当我检查用户时,创建了一个用户:“ AnonymousUser”。
from django.contrib.auth import get_user_model
User = get_user_model()
User.objects.all()[0].__dict__
{
'_state': <django.db.models.base.ModelState object at 0x7fc0cb644c50>,
'id': 1,
'password': '!ckXY3T...wUhuko52q',
'last_login': None,
'is_superuser': False,
'username': 'AnonymousUser',
'first_name': '',
'last_name': '',
'email': '',
'is_staff': False,
'is_active': True,
'date_joined': datetime.datetime(2019, 5, 2, 8, 22, 32, 317584, tzinfo=<UTC>)
}
使用Django标准身份验证模型时,默认情况下未创建用户。
我的设置和自定义用户模型如下:
# settings.py
# Authentication
AUTH_USER_MODEL = 'accounts.CustomUser'
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_USERNAME_REQUIRED = False
ACCOUNT_AUTHENTICATION_METHOD = 'email'
ACCOUNT_USER_MODEL_USERNAME_FIELD = 'username'
ACCOUNT_UNIQUE_EMAIL = True
ACCOUNT_SIGNUP_PASSWORD_ENTER_TWICE = True
ACCOUNT_SESSION_REMEMBER = True
ACCOUNT_AUTHENTICATED_LOGIN_REDIRECTS = False
ACCOUNT_EMAIL_VERIFICATION = 'mandatory'
ACCOUNT_LOGOUT_ON_PASSWORD_CHANGE = True
# accounts.models.py
from django.contrib.auth.models import AbstractUser
class CustomUser(AbstractUser):
def __str__(self):
return self.email
在allauth文档中,或者通过谷歌搜索“ allauth AnonymousUser created”的变体,我找不到任何与此相关的文档。
为什么使用allauth创建用户,我如何禁用此功能?