Creating a student registration view

Edit the views.py file of the students application and write the following code:

from django.urls import reverse_lazyfrom django.views.generic.edit import CreateViewfrom django.contrib.auth.forms import UserCreationFormfrom django.contrib.auth import authenticate, loginclass StudentRegistrationView(CreateView):    template_name = 'students/student/registration.html'    form_class = UserCreationForm    success_url = reverse_lazy('student_course_list')    def form_valid(self, form):        result = super(StudentRegistrationView,                       self).form_valid(form)        cd = form.cleaned_data        user = authenticate(username=cd['username'],                            password=cd['password1'])        login(self.request, user)        return result

This is the view that allows students to ...

Get Django 2 by Example 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.