繁体   English   中英

带有自定义用户模型django-allauth的AssertionError

[英]AssertionError with custom user model django-allauth

我是django的新手,最近我决定将django allauth集成以使用(facebook和google +)登录名,我使用自定义模型(django 1.5)和一对一的用户配置文件模型,我的自定义模型类看起来

class MyUser(AbstractBaseUser):   
   email = models.EmailField(
      verbose_name='email address',
      max_length=255,
      unique=True,
      db_index=True,
   )
   username = models.CharField(max_length=35,  blank=False)
   is_active = models.BooleanField (default=False)
   is_admin = models.BooleanField (default=False)

  objects = MyUserManager()

  USERNAME_FIELD = 'email'
  REQUIRED_FIELDS = ['username']

和我的用户个人资料:

class UserProfile(models.Model):
   phone = models.FloatField(blank=True, null=True)
   is_visible = models.BooleanField (default=True)
   user = models.OneToOneField(MyUser, primary_key=True)

这是django allauth local_settings文件:

ACCOUNT_AUTHENTICATION_METHOD = "email"
ACCOUNT_SIGNUP_FORM_CLASS = 'bloodi.accounts.forms.RegistrationForm'
ACCOUNT_LOGOUT_ON_GET = True
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_UNIQUE_EMAIL = True

在这种配置下,我遇到了django allauth的两个问题:
*)不允许重复的用户名*)应用程序在注册过程中崩溃(似乎用户帐户必须处于活动状态才能继续登录)

AssertionError 
Exception Location: \allauth\account\utils.py in perform_login, line 110
...
assert user.is_active

Django不允许重复的用户名,请参阅:

https://docs.djangoproject.com/en/dev/topics/auth/customizing/#django.contrib.auth.models.CustomUser.USERNAME_FIELD

至于断言错误,请使用:

is_active = models.BooleanField(default=True)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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