accounts/views.py
def register_user(request):
    """Create UserRegistrationForm, return form else validate and create CustomUser instance."""
    if request.user.is_authenticated():
        return HttpResponseRedirect(reverse('home_page'))

    if request.method == 'POST':
        form = UserRegistrationForm(request.POST, host=request.get_host())

        if form.is_valid():
            username = form.cleaned_data.get('username')
            form.save()
            user = authenticate(
                username=username,
                password=form.cleaned_data.get('password1')
            )

            if user is None or not user.is_active:
                messages.info(request, 'Check email')
                return render(request, 'accounts/check_email.html')
            else:
                messages.error(
                    request, 'There was an error creating the user. Kindly email admin.')

        else:
            messages.error(request, 'Invalid data! Check listed errors.')
    else:
        form = UserRegistrationForm()

    return render(request, 'accounts/register_user.html', {'form': form})
Create UserRegistrationForm, return form else validate and create CustomUser instance.
Create UserRegistrationForm, return form else validate and create CustomUser instance.
Create UserRegistrationForm return form else validate and create CustomUser instance .
def register_user(request):
    if request.user.is_authenticated():
        return HttpResponseRedirect(reverse('home_page'))
    if request.method == 'POST':
        form = UserRegistrationForm(request.POST, host=request.get_host())
        if form.is_valid():
            username = form.cleaned_data.get('username')
            form.save()
            user = authenticate(
                username=username,
                password=form.cleaned_data.get('password1')
            )
            if user is None or not user.is_active:
                messages.info(request, 'Check email')
                return render(request, 'accounts/check_email.html')
            else:
                messages.error(
                    request, 'There was an error creating the user. Kindly email admin.')
        else:
            messages.error(request, 'Invalid data! Check listed errors.')
    else:
        form = UserRegistrationForm()
    return render(request, 'accounts/register_user.html', {'form': form})
def register_user ( request ) : if request . user . is_authenticated ( ) : return HttpResponseRedirect ( reverse ( 'home_page' ) ) if request . method == 'POST' : form = UserRegistrationForm ( request . POST , host = request . get_host ( ) ) if form . is_valid ( ) : username = form . cleaned_data . get ( 'username' ) form . save ( ) user = authenticate ( username = username , password = form . cleaned_data . get ( 'password1' ) ) if user is None or not user . is_active : messages . info ( request , 'Check email' ) return render ( request , 'accounts/check_email.html' ) else : messages . error ( request , 'There was an error creating the user. Kindly email admin.' ) else : messages . error ( request , 'Invalid data! Check listed errors.' ) else : form = UserRegistrationForm ( ) return render ( request , 'accounts/register_user.html' , { 'form' : form } )
Create UserRegistrationForm, return form else validate and create CustomUser instance.
Create UserRegistrationForm return form else validate and create CustomUser instance .
"""Create UserRegistrationForm, return form else validate and create CustomUser instance."""
request