簡體   English   中英

如何在Django Deliciouspie JSON上附加success = true

[英]How to append success=true on django tastypie json

我正在使用django-tastypie實現restapi,我正在使用sencha作為移動客戶端。 我需要出於某些目的操縱響應文本。

像下面

form.submit({
    success: function() {
        // The callback function is run when the user taps the 'ok' button
        form.reset();

        //Ext.Msg.alert('Thank You', 'Your message has been received', function() {
        //  form.reset();
        //});
    }
});

我有JSON響應如下

{"meta": {"limit": 20, "next": null, "offset": 0, "previous": null, "total_count": 13},       
 "objects": [{"body": "This will prbbly be my lst edited  post.", "id": 1,
 "pub_date":  "2011-05-22", "resource_uri": "/api/v1/entry/1/", "slug": "another-post", 
 "title": "Another Post"}, {"body": "This will prbbly be my lst post.", "id": 2, 
 "pub_date": "2011-05-22", "resource_uri": "/api/v1/entry/2/", "slug": "another-post", 
 "title": "Another Post"}, {"body": "This will prbbly be my lst edited  post"}]}

發送成功=> true非常重要如果成功未定義或不等於true,則將其視為表單提交錯誤。 如何在Django Deliciouspie JSON上附加success = true

如果我正確理解了您的問題,您想在API調用的結果后附加{'success': true} ,對嗎? 如果是這樣,則可以在Resource類上重寫dehydrate方法:

def dehydrate(self, bundle):
    bundle.data['success'] = True
    return bundle

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM