gpt4 book ai didi

angularjs - DRF/Angular : form data with nested objects with dotted/[] notation

转载 作者:行者123 更新时间:2023-12-03 08:06:13 26 4
gpt4 key购买 nike

我正在像这样将表单数据发送到 Django Rest Framework View,用于名为 security 的嵌套对象的所有序列化数据:

------WebKitFormBoundaryAOygB8mq3Oo5I7ii
Content-Disposition: form-data; name="security[title]"

P

它失败并显示 400 错误,指出字段 security 是必需的。

当我使用 DRF 的 Web View 并在那里填写表格时,发布它我看到符号是这样的

------WebKitFormBoundaryAOygB8mq3Oo5I7ii
Content-Disposition: form-data; name="security.title"

P

因为我将 Angular 与 ng-upload 及其上传库(咖啡)一起使用:

    Upload.upload(
url: '/services/rest/.../'+id+'/upload'
data:
$scope.object)

发送表单数据。

哪个问题是正确的?点或 [] 符号?固定哪一边?

最佳答案

发现:上传lib可以通过objectKey: '.k'配置

细节:
*data: {key: file, otherInfo: uploadInfo},
/*
This is to accommodate server implementations expecting nested data object keys in .key or [key] format.
Example: data: {rec: {name: 'N', pic: file}} sent as: rec[name] -> N, rec[pic] -> file<br/>
data: {rec: {name: 'N', pic: file}, objectKey: '.k'} sent as: rec.name -> N, rec.pic -> file */<br/>
objectKey: '[k]' or '.k' // default is '[k]'

关于angularjs - DRF/Angular : form data with nested objects with dotted/[] notation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33724715/

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