get request parameters in Tastypie

佐手、 提交于 2019-12-30 07:07:46

问题


I am building a REST API for my application that uses a NoSQL db (Neo4j) using Tastypie.

So I overrode some main methods of the class tastypie.resources.Resource to do so, and currently struggling to implement def obj_get_list(self, request=None, **kwargs): which is supposed to return a list of objects.

Actually, I want to pass a parameter to this method through the url (something like http://127.0.0.1:8000/api/airport/?query='aQuery' ) and then perform a query based on this parameter.

The problem is that the request is None so I can't get its parameter !

When printing the kwargs variable, I see this :

{'bundle': <Bundle for obj: '<testNeo4Django.testapp.api.Airport object at 0x9d829ac>' and with data: '{}'>}

Thanks for your help


回答1:


Currently positional argument request is not passed toobj_get_list.

So you should:

def obj_get_list(self, bundle, **kwargs):

    param =  bundle.request.GET['param']
    #fetch objects based on param
    return objects


来源:https://stackoverflow.com/questions/16981191/get-request-parameters-in-tastypie

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!