Register

THE USER REGISTRATION FORM CLASS

Django

Let’s go immediately to create the form. We should use a ModelForm as there is already a user model in Django. The User object. This object contains several fields some of which are not necessary for a registration form. Let’s see the code.

Register Form

In this case we have to validate two fields password and confirm_password, and the clean_field_name function is not good. We can use the clean() function for this purpose. I am now going to create the function in views.py which will use the form.

file views.py

Once the User object has been created, we authenticate it and log in, before redirecting the user to the home page. Let’s see the registration template:

registrazione.html

NB: Remember to register the view in urls.py. We run the development server and create a user. Once created you can see from the Django Admin panel that this user does not have staff privileges.

Django Admin

LINKS TO PREVIOUS POST

PREVIOUS POST LINKS

LINK TO THE CODE ON GITHUB

GITHUB