I'm using Django-Registration and the form just has 3 fields (Username, Email, Password, and Re-password), but why I can't add last name and first name??
In the Form all is fine but the User Model just accepts 3 arguments:
new_user = User.objects.create_user(username, email, password)
but why I can't do that:
new_user = User.objects.create_user(username, email, password, first_name ,last_name)
The Django Documentation doesn't say anything about just 3 arguments; all tutorials on the net just use 3 arguments...
Why?? Or how will I make use of first and last name?
Even though the username field is marked as unique, by default it is not case-sensitive.
Create Sign Up Form If you are new to Django form, refer Django form tutorial. Create forms.py file if it is not present and add the following class for the sign-up form. For creating sign up form, we can use the Django UserCreationForm . Create a view to process the signup data and save that data into the database.
I did it :
new_user = User.objects.create_user(username, email, password)
new_user.is_active = False
new_user.first_name = first_name
new_user.last_name = last_name
new_user.save()
I know you found a way around, but this way below may also interest you.
This is because it requires keywords arguments (which will be passed to the User's __init__
method).
https://docs.djangoproject.com/en/3.2/ref/contrib/auth/#manager-methods
User.objects.create_user("user1", "[email protected]", "pwd", first_name="First", last_name="Last")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With