【问题标题】:How do I update a list data_relation in Python Eve如何在 Python Eve 中更新列表 data_relation
【发布时间】:2014-11-07 22:53:32
【问题描述】:

我有一个模型“用户”和它的架构,其中包括与用户的一对多关系:

'followers': {
    'type': 'list',
    'schema': {
            'type': 'objectid',
            'data_relation': {
                    'resource': 'users'
            }
    }
},

我正在尝试更新关注者列表。我尝试使用“关注者”键和对象 ID 列表向 /users/545c7dccb505970bbf0e5ad1 端点发送 PATCH 请求,但它不起作用。还尝试向 /users/545c7dccb505970bbf0e5ad1/followers/ 发送 PUT 请求,但没有成功。

那么如何使用 Python Eve REST API 将对象添加到此列表中?

GET /users/545c7dccb505970bbf0e5ad1/
{
    "_updated": "Fri, 07 Nov 2014 08:07:40 GMT",
    "public_key": "test",
    "_etag": "256d6da738a0f39929d40d1c868e1f67661460be",
    "_links": {
        "self": {
            "href": "/users/545c7dccb505970bbf0e5ad1",
            "title": "User"
        },
        "parent": {
            "href": "",
            "title": "home"
        },
        "collection": {
            "href": "/users",
            "title": "users"
        }
    },
    "active": false,
    "_created": "Fri, 07 Nov 2014 08:07:40 GMT",
    "_id": "545c7dccb505970bbf0e5ad1"
}

PATCH /users/545c7dccb505970bbf0e5ad1
{
    "_status": "ERR",
    "_error": {
        "message": "You don't have the permission to access the requested resource. It is either read-protected or not readable by the server.",
        "code": 403
    }
}

PUT /users/545c7dccb505970bbf0e5ad1/followers
{
    "_status": "ERR",
    "_error": {
        "message": "The requested URL was not found on the server.  If you entered the URL manually please check your spelling and try again.",
        "code": 404
    }
}

【问题讨论】:

    标签: python eve datarelation


    【解决方案1】:

    doesn't work 非常广泛...但是猜测您需要发送您的_etag 令牌,服务器在获取或创建用户时返回...这是防止从过时模型更新所必需的

    【讨论】:

    • 服务器在哪里返回_netid令牌?这是某种标题吗?我在 JSON 中看不到它。
    • 谢谢,这行得通。我必须在请求中添加“If-Match”标头并将 _etag 值放在那里。
    • 另外,Eve 文档也有专门讨论 concurrency and data integrity control 的部分。您在回复中收到了422 Precondition Failed(顺便说一下,这个细节值得在您的问题中发布),正是因为您的请求中缺少 ETag。
    猜你喜欢
    • 1970-01-01
    • 2016-05-16
    • 1970-01-01
    • 2015-06-21
    • 2016-09-08
    • 2021-04-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多