[Fixed]-Having trouble returning a User object with Django

0👍

Okay I figured it out, I just need to create the user in my code first. I just added user = User.objects.create_user('charlie', 'charlesdsmith25@gmail.com', 'smith') so now it’s:

def sign_in(request):
    #we need to handle all the data that was just typed, we'll add a condition for that
    form = NameForm(request.POST)
    if form.is_valid():
        post = form.save()
        post.save()
        username = request.POST.get('username')
        password = request.POST.get('password')
        user = User.objects.create_user('charlie', 'charlesdsmith25@gmail.com', 'smith')
        auth = authenticate(username=username, password=password)
        if user is not None:
            login(request,user)
            return HttpResponse('hi')
        else:
            return HttpResponse('bye')
    else:
        form = NameForm()
    return render(request, 'checkin/sign_in_new.html', {'form': form})
👤Amon

1👍

The user doesn’t exist. Go to admin and create one first. And yes user needs to be created before you attempt to sign in.

Leave a comment