5
我試圖用得-AUTH提供的串行器爲GET(*與標題)用戶詳細信息從定義的endpoint /休息-AUTH /用戶/字段名`username`是無效的模型
(帶*頭 (內容類型:應用程序/ JSON 授權:令牌1a5472b2af03fc0e9de31fc0fc6dd81583087523 ))
我正在以下回溯:https://dpaste.de/oYay#L
我已經定義自定義用戶模型(使用電子郵件,而不是用戶名)這樣:
class UserManager(BaseUserManager):
def create_user(self, email, password, **kwargs):
user = self.model(
# lower-cases the host name of the email address
# (everything right of the @) to avoid case clashes
email=self.normalize_email(email),
is_active=True,
**kwargs
)
user.set_password(password)
user.save(using=self._db)
return user
def create_superuser(self, email, password, **kwargs):
user = self.model(
email=email,
is_staff=True,
is_superuser=True,
is_active=True,
**kwargs
)
user.set_password(password)
user.save(using=self._db)
return user
class MyUser(AbstractBaseUser, PermissionsMixin):
USERNAME_FIELD = 'email'
email = models.EmailField(unique=True)
設置如下:
AUTH_USER_MODEL = 'users.MyUser'
ACCOUNT_USER_MODEL_USERNAME_FIELD = None
# Config to make the registration email only
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_UNIQUE_EMAIL = True
ACCOUNT_EMAIL_VERIFICATION = 'optional'
ACCOUNT_USERNAME_REQUIRED = False
ACCOUNT_AUTHENTICATION_METHOD = 'email'
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
不知道如何去糾正這個錯誤..所以它與其餘-auth的序列化器的要求。
這個解決方案的工作對我很好,只是一個細節,以改善答案供將來參考: 在settings.py中使用代碼如下: 'REST_AUTH_SERIALIZERS = { 'USER_DETAILS_SERIALIZER':'users.serializers.CustomUserDetailsS erializer' }' – Anon957