Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I have written a login view using build-in auth ,django
auth.login()
gives 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)
You have a function def login
and a library import with the same name.
What you need is to change one of them.
Example :
- def user_login // import login as Login_process
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.