Django& DeliciousPie:request.POST为空 [英] Django & TastyPie: request.POST is empty

查看:80
本文介绍了Django& DeliciousPie:request.POST为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用curl进行POST:

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/

但是,request.POST始终为空。

However, request.POST is always empty.

下面是我的ModelResource代码:

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?

预先感谢。

推荐答案

从Django 1.5开始,POST不再包含非格式数据。他们现在在request.body中。

Starting at Django 1.5, 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

这篇关于Django& DeliciousPie:request.POST为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆