问题
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