[英]"detail": "Method \"POST\" not allowed."
here i tried with custom user login in djangorestfulapi but i am getting error that "detail": "Method \\"POST\\" not allowed."在这里,我尝试在 djangorestfulapi 中使用自定义用户登录,但我收到“详细信息”错误:“不允许方法\\“POST\\”。” . . can anybody please explain where i am getting wrong?有人可以解释一下我哪里出错了吗?
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.")
endpoint url:端点网址:
path('api/login/',LoginAPIView.as_view(), name='login'),
In class based views, you should define separate method for separate http methods like this在基于类的视图中,您应该为这样的单独 http 方法定义单独的方法
class LoginAPIView(APIView):
def post(self,request,format=None):
user = ''' SELECT * FROM users '''
# Gather the username and password provided by the user.
username = request.POST.get('username')
password = request.POST.get('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")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.