Registering New Users
00:00 Registering New Users. Your application can now handle all URLs related to Django user management, but one feature isn’t working yet. You may have noticed there’s no option to create a new user. Unfortunately, Django doesn’t provide user registration out of the box. You can, however, add it on your own. Django offers lots of forms that you can use in your projects.
One of them is
UserCreationForm. It contains all the necessary fields to create a new user, but it doesn’t include an email field. In many applications, this might not be a problem, but you’ve already implemented a password reset feature.
As you can see, your
CustomUserCreationForm extends Django’s
UserCreationForm. The inner class
Meta keeps additional information about the form and in this case extends
UserCreationForm.Meta, so almost everything from Django’s form will be reused.
The key difference is the
fields attribute, which determines the fields that will be included in the form. Your custom form will use all the fields from
UserCreationForm and will add the
03:38 This is very similar to the previous templates. As before, it takes the form from the context and renders it. The only difference is that this time you had to add the form to the context on your own, instead of letting Django do it.
04:40 Please keep in mind that this is a bare-bones example of a registration form. In the real world, you would also display proper error messages if someone had tried to register an account that already exists. In addition, you would probably send emails with confirmation links after someone creates a user account. To do that, your site would need to be able to send emails to the outside world.
Become a Member to join the conversation.