здесь я попытался с пользовательским логином в djangorestfulapi, но я получаю сообщение об ошибке "detail": "Метод \" POST \ "не разрешен". , Кто-нибудь может объяснить, где я ошибаюсь?
class LoginAPIView(APIView):
def user_login(self,request,format=None):
# context = RequestContext(request)
if request.method == 'POST':
user = ''' SELECT * FROM users '''
# Gather the username and password provided by the user.
username = request.POST['username']
password = request.POST['password']
user = authenticate(username=username, password=password)
print("auth",str(authenticate(username=username, password=password)))
if user:
# Is the account active? It could have been disabled.
if user.is_active:
login(request, user)
return HttpResponseRedirect('/')
else:
return HttpResponse("xxx")
else:
# Bad login details were provided. So we can't log the user in.
print ("Invalid login details: {0}, {1}".format(username, password))
return HttpResponse("Invalid login details supplied.")
URL-адрес конечной точки:
path('api/login/',LoginAPIView.as_view(), name='login'),