Django:“;django.http.request.RawPostDataException:在读取请求';s数据流“;
每次尝试登录此用户时,我都会收到一个错误。以下是相关的回溯:Django:“;django.http.request.RawPostDataException:在读取请求';s数据流“;,django,django-rest-framework,Django,Django Rest Framework,每次尝试登录此用户时,我都会收到一个错误。以下是相关的回溯: AttributeError: 'Request' object has no attribute 'body' During handling of the above exception, another exception occurred: raise RawPostDataException("You cannot access body after reading from request's data stream")
AttributeError: 'Request' object has no attribute 'body'
During handling of the above exception, another exception occurred:
raise RawPostDataException("You cannot access body after reading from request's data stream")
django.http.request.RawPostDataException: You cannot access body after reading from request's data stream
这在my views.py中:
@api_view(['POST'])
def login(request):
email = request.POST['email']
password = request.POST['password']
user = authenticate(email=email, password=password)
if user is not None:
login(request)
print("Breakpoint")
return Response(status=status.HTTP_200_OK)
print('something went wrong')
return Response(status=status.HTTP_401_UNAUTHORIZED)
这可能是因为函数名中存在冲突 您可能已导入身份验证登录名
from django.contrib.auth import login
同时,您的登录视图名为login
。因此产生了冲突
尝试将导入更改为
from django.contrib import auth
然后修改登录
查看为:
if user is not None:
auth.login(request)
你是我的英雄。是的,我以前遇到过一些类似的问题,所以我不得不导入模块。