【问题标题】:Restless - "objects" wrapperRestless - “对象”包装器
【发布时间】:2015-05-13 15:14:14
【问题描述】:

我正在使用 Restless 和 as stated in the documentation,返回 Model.objects.all() 会产生如下内容:

{
    "objects": [
        {
            "id": 1,
            "title": "First Post!",
            "author": "daniel",
            "body": "This is the very first post on my shiny-new blog platform...",
            "posted_on": "2014-01-12T15:23:46",
        },
        {
            # More here...
        }
    ]
}

这很好用。但是,我不希望“对象”包装器出现在这里。我的前端代码需要一个数组。 有没有办法告诉 Restless 不要包装数组?

【问题讨论】:

标签: django flask-restless


【解决方案1】:

您可以通过覆盖方法Resource.wrap_list_response() 来做到这一点。默认实现只是将数据包装在字典中(在 objects 键内),您可以修改它以返回数据不变。

【讨论】:

    猜你喜欢
    • 2017-07-02
    • 1970-01-01
    • 2011-02-25
    • 1970-01-01
    • 2013-11-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-17
    相关资源
    最近更新 更多