每次尝试登录此用户时,我都会收到错误消息。以下是相关的回溯:
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
这是在我的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)
发布于 2017-02-23 04:00:21
这可能是因为你在函数名中有冲突。
您可能已经将auth.login
导入为
from django.contrib.auth import login
同时,您的登录视图被命名为login
。这就是冲突的原因。
尝试将导入更改为
from django.contrib import auth
然后修改login
视图为:
if user is not None:
auth.login(request)
https://stackoverflow.com/questions/42400965
复制相似问题