[Django]-Django Allauth how to change username=first_name?

2👍

I think it will be a short matter of time before your users start seeing conflicts with the generated usernames. As soon as you have more than one “John Smith” then you’ll have a problem.

Also, many users may prefer not to have their full name as their username.

Personally, I always use email for the login, never usernames, but if you’re adamant about it, I’d recommend that you show a form allowing the choice of username and giving the default as "%s %s" % (first_name, last_name) or similar.

To ensure the form is displayed, edit settings:

SOCIALACCOUNT_AUTO_SIGNUP = False  # require social accounts to use the signup form

From the documentation:

[If true] Attempt to bypass the signup form by using fields (e.g. username,
email) retrieved from the social account provider. If a conflict
arises due to a duplicate e-mail address the signup form will still
kick in.

You should be able to use a hook to supply the suggested username before the form is rendered.

A working example* of django-allauth with Twitter Bootstrap is at https://github.com/aellerton/demo-allauth-bootstrap. However, it does not use usernames but it does show the signup form after social signup.

*Disclaimer: I wrote the example.

Leave a comment