TypeError: login () takes 1 positional argument, but 2 are given

I wrote a login using buid in auth, django auth.login () gives the above error my code with error code o 500

from rest_framework.response import Response from rest_framework import status from rest_framework.decorators import api_view from django.contrib.auth.models import User from django.contrib.auth import authenticate,logout,login @api_view(['POST']) def register(request): user=User.objects.create_user(username=request.POST['username'],email=request.POST['email'],password=request.POST['password']) return Response({'ok':'True'},status=status.HTTP_201_CREATED) @api_view(['POST']) def login(request): user=authenticate( username=request.POST['username'], password=request.POST['password'] ) if user is not None: login(request,user) return Response({'ok':'True'},status=status.HTTP_200_OK) else: return Response({'ok':'False'},status=status.HTTP_401_UNAUTHORIZED) 
+24
django django-authentication
source share
2 answers

Your view has the same name as the auth login function, so it hides it. Change the name of the view or import the function under a different name, for example from django.contrib.auth import login as auth_login .

+71
source share

You have a def login function and an import library with the same name.

You need to change one of them.

Example:

 - def user_login // import login as Login_process 
0
source share

All Articles