Authenticate return None

I always get None value from authenticate function through I have registered user when testing by using Postman and I also try using Django Shell.

def test_login(request: HttpRequest):
    if request.method == "POST":
        data = request.POST
        username = data.get('username', None)
        password = data.get('password', None)
        user = authenticate(request,username=username,password=password)
        if user:
            return JsonResponse(data={"message":"User Found"})
        return JsonResponse(data={"message":"User Not Found"})

here is when I test in Django Shell

I have followed to Django tutorial Authenticating users, everything work fine but when I go to Rest Framework, it’s not working anymore. Please help me.

Welcome @phutuan123vn !

Side note: Please do not post images of code, templates, error messages, or terminal output here. Copy/paste the text into the body of your post, enclosed between lines of three backtick - ` characters. This means you’ll have a line of ```, then your code, then another line of ```. This forces the forum software to keep your code properly formatted.

How are you registering users?

What do you get if you run the following commands in the shell?

user = User.objects.get(username="ptt1")
1 Like

sry I think I know a error where it is. Thank you for your help, It’s remind me where I was wrong, Thank you so much