django-allauth set username the same as email

后端 未结 2 996
死守一世寂寞
死守一世寂寞 2021-01-12 04:01

I have a sign up form which asks only for email and password. When a user signs up, django-allauth creates a username for that user by striping the \"@email\" suffix form th

2条回答
  •  抹茶落季
    2021-01-12 04:19

    profiles.models.py (custom user model)

    from allauth.socialaccount.adapter import DefaultSocialAccountAdapter
    
    class CustomSocialAccountAdapter(DefaultSocialAccountAdapter):
    
        def populate_user(self, request, sociallogin, data):
            user = super().populate_user(request, sociallogin, data)
            user.username = user.email
            return user
    

    settings.py

    SOCIALACCOUNT_ADAPTER = "profiles.models.CustomSocialAccountAdapter"
    

提交回复
热议问题