Skip to Main Content
Python Programming Blueprints
book

Python Programming Blueprints

by Daniel Furtado, Marcus Pennington
February 2018
Intermediate to advanced content levelIntermediate to advanced
456 pages
9h 56m
English
Packt Publishing
Content preview from Python Programming Blueprints

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): ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Intelligent Projects Using Python

Intelligent Projects Using Python

Santanu Pattanayak, Manohar Swamynathan
Flask Blueprints

Flask Blueprints

Joël Perras
Matplotlib for Python Developers - Second Edition

Matplotlib for Python Developers - Second Edition

Aldrin Yim, Claire Chung, Allen Yu

Publisher Resources

ISBN: 9781786468161Supplemental Content