gpt4 book ai didi

Django & TastyPie : request. POST 为空

转载 作者:行者123 更新时间:2023-12-04 00:01:48 25 4
gpt4 key购买 nike

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

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

但是, 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())

有人知道我错过了什么吗?

提前致谢。

最佳答案

从 Django 1.5 开始,request.POST不再包含非表单数据。他们现在在 request.body .
https://docs.djangoproject.com/en/dev/ref/request-response/#django.http.HttpRequest.POST

关于Django & TastyPie : request. POST 为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16213324/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com