5
我在發佈到我的API時遇到了問題,無法完全弄清楚錯誤是指什麼。如果它很重要,我使用Django REST幷包含回溯。'WSGIRequest'對象沒有屬性'data'
if (repeat == false) {
post_data = {'User': usernameInput}
$.ajax({
type: 'POST',
url: '/0/addUser',
data: post_data,
async: true
})
}
class AddUser(APIView):
def post(self, request, format = None):
serializer = UserSerializer(data=request.data)
if serializer.isvalid():
serializer.save()
return Response(serializer.data, status=status.HTTP_201_CREATED)
Traceback:
File "/Library/Python/2.7/site-packages/django/core/handlers/base.py" in get_response
111. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Library/Python/2.7/site-packages/django/views/decorators/csrf.py" in wrapped_view
57. return view_func(*args, **kwargs)
File "/Library/Python/2.7/site-packages/django/views/generic/base.py" in view
69. return self.dispatch(request, *args, **kwargs)
File "/Library/Python/2.7/site-packages/rest_framework/views.py" in dispatch
403. response = self.handle_exception(exc)
File "/Library/Python/2.7/site-packages/rest_framework/views.py" in dispatch
400. response = handler(request, *args, **kwargs)
File "/Users/rae/Desktop/112/djangotemplate/notes/views.py" in post
23. serializer = UserSerializer(data=request.data)
File "/Library/Python/2.7/site-packages/rest_framework/request.py" in __getattr__
436. return getattr(self._request, attr)
我正在使用3.0.4,並得到相同的錯誤。我正在使用中間件來存儲調試請求,並且在'process_response'嘗試調用'request.data'給了我'沒有屬性'數據'錯誤。想法? – awidgery 2015-02-11 10:47:18
我正在使用djangorestframework-jwt 1.9.0的DRF 3.5.3,並且也看到了這個錯誤。有什麼想法嗎? – 2017-01-09 05:05:53