我正在为我的应用程序构建一个 REST API,该应用程序使用 Tastypie 的 NoSQL db (Neo4j).
I am building a REST API for my application that uses a NoSQL db (Neo4j) using Tastypie.
所以我重写了类 tastypie.resources.Resource
的一些主要方法,目前正在努力实现 def obj_get_list(self, request=None, **kwargs):
应该返回一个对象列表.
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.
实际上,我想通过 url 将参数传递给此方法(类似于 http://127.0.0.1:8000/api/airport/?query='aQuery'
)然后根据此参数执行查询.
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.
问题是请求是 None
所以我不能得到它的参数!
The problem is that the request is None
so I can't get its parameter !
在打印 kwargs 变量时,我看到了这个:
When printing the kwargs variable, I see this :
{'bundle': <Bundle for obj: '<testNeo4Django.testapp.api.Airport object at 0x9d829ac>' and with data: '{}'>}
感谢您的帮助
当前位置参数 request
没有传递给obj_get_list
.
Currently positional argument request
is not passed toobj_get_list
.
所以你应该:
def obj_get_list(self, bundle, **kwargs):
param = bundle.request.GET['param']
#fetch objects based on param
return objects
这篇关于在 Tastypie 中获取请求参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!