'WSGIRequest' object has no attribute 'data'

chrae

I'm having trouble with posting to my API and can't quite figure out what the error is referring to. If it matters, I'm using Django REST and included the traceback.

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)
Kevin Brown

Django REST Framework has its own Request object that wraps the HttpRequest object passed in by Django and adds some additional functionality (like custom rendering and another authentication layer). If any properties are accessed on the Request object that don't exist, it will automatically proxy it to the underlying HttpRequest, so typically you don't notice the difference.

In DRF 2.x, the Request property has DATA and FILES properties that store the passed in data as well as any files which have been detected. These were combined in DRF 3.0 and replaced with a single data property. As DRF 3.0 has been released, all of the documentation now reflects the new Request.data property.

You appear to be using Django REST Framework 2.x, but you are trying to access the new property introduced in DRF 3.0. Because it doesn't exist on the Request object, it is being proxied down to the HttpRequest object, where it also isn't being found.

Este artigo é coletado da Internet.

Se houver alguma infração, entre em [email protected] Delete.

editar em
0

deixe-me dizer algumas palavras

0comentários
loginDepois de participar da revisão

Artigos relacionados

Django 'WSGIRequest' object has no attribute 'data'

'WSGIRequest' object has no attribute method

WSGIRequest' object has no attribute 'session_key

django pagination error: AttributeError: 'WSGIRequest' object has no attribute 'Get'

Django : 'WSGIRequest' object has no attribute 'user'? - AuthenticationMiddleware & SessionAuthenticationMiddleware are in sequence

AttributeError: 'WSGIRequest' object has no attribute 'get' while making a get request

DRF forms - 'str' object has no attribute 'data'

'Request' object has no attribute 'add_data'

AttributeError: 'Node' object has no attribute 'data'

AttributeError: 'dict' object has no attribute 'data'

"remoteContext object has no attribute"

AttributeError: 'builtin_function_or_method' object has no attribute 'data'

'class' object has no attribute 'object'

Attribute Error: 'QueryDict' object has no attribute 'iterlists'

Attribute Error:'NoneType' object has no attribute 'parent'

<Class> Object has no attribute <attribute_name>

Attribute Error at/ 'str' object has no attribute 'makefile'

'NaTType' object has no attribute 'days'

'RawTurtle' object has no attribute 'Turtle'

'dict' object has no attribute 'push'

Django: AttributeError: "Object has no attribute"

'SparkContext' object has no attribute 'textfile'

'module' object has no attribute 'unescape'

'Blueprint' object has no attribute 'config'

ResNet object has no attribute 'predict'

'list object' has no attribute 'name'

Iterparse object has no attribute next

Django form: object has no attribute

Django 'dict' object has no attribute