[Answered ]-Redirect to home as a logged in user after successful registration

2👍

Maybe, this can solve your problem.
This will authenticate and login the user after registration.

def register(request):
    if request.method == "POST":
        form = UserCreationForm(request.POST)
        if form.is_valid():
            user = form.save()
            password = self.request.POST.get('password', None)
            authenticated = authenticate(
                username=user.username,
                password=password
            )
            if authenticated:
                login(request, authenticated)
                return redirect("/")
    else:
        form = UserCreationForm()
    return render(request, 'register.html', {
        'form': form
    })

Leave a comment