get request parameters in Tastypie(在 Tastypie 中获取请求参数)
问题描述
我正在为我的应用程序构建一个 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 中获取请求参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 Tastypie 中获取请求参数


- YouTube API v3 返回截断的观看记录 2022-01-01
- CTR 中的 AES 如何用于 Python 和 PyCrypto? 2022-01-01
- 使用 Cython 将 Python 链接到共享库 2022-01-01
- 使用公司代理使Python3.x Slack(松弛客户端) 2022-01-01
- 计算测试数量的Python单元测试 2022-01-01
- ";find_element_by_name(';name';)";和&QOOT;FIND_ELEMENT(BY NAME,';NAME';)";之间有什么区别? 2022-01-01
- 如何使用PYSPARK从Spark获得批次行 2022-01-01
- 检查具有纬度和经度的地理点是否在 shapefile 中 2022-01-01
- 我如何卸载 PyTorch? 2022-01-01
- 我如何透明地重定向一个Python导入? 2022-01-01