django set up signup form code example

Example: signup view

from django.contrib.auth import authenticate

class SignUpView(CreateView):
    form_class 		= UserRegistrationForm
    success_url 	= reverse_lazy('home')
    template_name	= 'registration/signup.html'
    
    def form_valid(self, form):
        view        = super(SignUpView, self).form_valid(form)
        username    = form.cleaned_data.get('username')
        password    = form.cleaned_data.get('password1')
        user        = authenticate(username=username, password=password)       
        login(self.request, user)
        return view