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 中获取请求参数
基础教程推荐
- 对多索引数据帧的列进行排序 2022-01-01
- 比较两个文本文件以找出差异并将它们输出到新的文本文件 2022-01-01
- Kivy 使用 opencv.调整图像大小 2022-01-01
- 在 Python 中将货币解析为数字 2022-01-01
- matplotlib 设置 yaxis 标签大小 2022-01-01
- 究竟什么是“容器"?在蟒蛇?(以及所有的 python 容器类型是什么?) 2022-01-01
- 在 Django Admin 中使用内联 OneToOneField 2022-01-01
- Python,确定字符串是否应转换为 Int 或 Float 2022-01-01
- Python 中是否有任何支持将长字符串转储为块文字或折叠块的 yaml 库? 2022-01-01
- kivy 应用程序中的一个简单网页作为小部件 2022-01-01
