相关疑难解决方法(0)

Django&TastyPie:request.POST为空

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

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

但是,request.POST始终为空.

下面是我的ModelResource代码:

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())
Run Code Online (Sandbox Code Playgroud)

谁知道我错过了什么?

提前致谢.

django tastypie

12
推荐指数
1
解决办法
1万
查看次数

标签 统计

django ×1

tastypie ×1