Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django & TastyPie: request.POST is empty

I'm trying to do a POST using curl:

curl --dump-header - -H "Content-Type: application/json" -X POST --data '{"item_id": "1"}' http://www.mylocal.com:8000/api/1/bookmarks/

However, request.POST is always empty.

Below is my ModelResource code:

class BookmarkResource(ModelResource):


    class Meta:
        queryset = Bookmark.objects.all()    
        resource_name = 'bookmarks'
        fields = ['id', 'tags']
        allowed_methods = ['get', 'post', 'delete', 'put']
        always_return_data = True
        authorization= Authorization()
        include_resource_uri = False

    def determine_format(self, request):
        return "application/json"

    def obj_create(self, bundle, **kwargs):

        request = bundle.request

        try:
            payload = simplejson.loads(request.POST.keys()[0])
        except:
            payload = simplejson.loads(request.POST.keys())

Anybody knows what I'm missing?

Thanks in advance.

like image 794
dannyroa Avatar asked Apr 25 '13 11:04

dannyroa


1 Answers

Starting at Django 1.5, request.POST does not contain non-form data anymore. They are now in request.body.

https://docs.djangoproject.com/en/dev/ref/request-response/#django.http.HttpRequest.POST

like image 70
dannyroa Avatar answered Oct 07 '22 00:10

dannyroa