Creating the views of the user creation

With the form and validation in place, we can now add the view that will handle the request to create a new account. Open the file views.py at gamestore/main, and start by adding some import statements:

from django.views.decorators.csrf import csrf_protectfrom .forms import SignupFormfrom django.contrib.auth.models import User

As we will be receiving data from a POST request, it is a good idea to add Cross-Site Request Forgery checkings, so we need to import the csrf_protect decorator.

We also import the SignupForm that we just created so we can pass it to the view or use it to parse the request data. Lastly, we import the User model.

So, let's create the signup function:

@csrf_protectdef signup(request): ...

Get Python Programming Blueprints now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.