1

我是 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
4

1 回答 1

1

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

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

至于断言错误,请使用:

is_active = models.BooleanField(default=True)
于 2013-09-18T15:29:15.247 回答