[Answer]-Django CreateView Auto Login

1👍

In the view that is responsible for registration add the following code if the registration is successfull:

from django.contrib.auth import authenticate, login, logout
user = authenticate(username=request.POST['username'], password=request.POST['password'])
if user is not None:
    if user.is_active:
        login(request, user)
        redirect('logged_in_url')
    else:
        redirect('user_not_active_url')
else:
    redirect('bad_username_or_password_url')

Leave a comment