Remove 'username' field from django-allauth

白昼怎懂夜的黑 提交于 2019-12-18 12:49:53

问题


When django-registration doesn't support django 1.5 and custom user model. I'm trying use django-allauth, from first look it's great product.

Problem i have - username field required, but in my app i don't have username's. So, allauth documentation says:

**Available settings:**
ACCOUNT_AUTHENTICATION_METHOD (="username" | "email" | "username_email")

Specifies the login method to use -- whether the user logs in by entering his username, e-mail address, or either one of both.

Ok, i done, and got error:

AssertionError at /accounts/signup/
No exception supplied

models.py:

class MyUser(AbstractBaseUser, PermissionsMixin):
    title = models.CharField ('Name', max_length=100)
    email = models.EmailField('Email', max_length=255, unique=True)
    ...

settings.py

ACCOUNT_USERNAME_REQUIRED = False
ACCOUNT_AUTHENTICATION_METHOD = ('email')
AUTH_USER_MODEL = 'internboard.MyUser'

What i'm doing wrong ?


回答1:


Thanks, i found, right settings for my task:

ACCOUNT_AUTHENTICATION_METHOD = 'email'
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_UNIQUE_EMAIL = True
ACCOUNT_USERNAME_REQUIRED = False



回答2:


If you encounter the error django.core.exceptions.FieldDoesNotExist: Account has no field named 'username' with reference to USER_MODEL_USERNAME_FIELD in the stacktrace, you'll also need to set ACCOUNT_USER_MODEL_USERNAME_FIELD to None (or the appropriate field for your use case). The full set of settings needed are the following:

ACCOUNT_AUTHENTICATION_METHOD = 'email'
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_UNIQUE_EMAIL = True
ACCOUNT_USER_MODEL_USERNAME_FIELD = None
ACCOUNT_USERNAME_REQUIRED = False

This setting is explained in more detail in the django-allauth documentation for Custom User Models with defaults outlined in Configuration.



来源:https://stackoverflow.com/questions/19683179/remove-username-field-from-django-allauth

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!