signup class 1

signup class

class SignUpView(generic.CreateView):
    form_class 			= UserCreationForm
    success_url 		= reverse_lazy('login')
    template_name		= 'registration/signup.html'
    
    def form_valid(self, form):
        view        = super(SignUp, 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

Here is what the above code is Doing:
1. We’re using the built-in UserCreationForm to create a new user.
2. We’re using reverse_lazy to redirect the user to the login page after they’ve successfully signed up.
3. We’re using the built-in login function to log the user in after they’ve successfully signed up.

Similar Posts