在 Tastypie 中获取请求参数

get request parameters in Tastypie(在 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 中获取请求参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

groupby multiple coords along a single dimension in xarray(在xarray中按单个维度的多个坐标分组)
Group by and Sum in Pandas without losing columns(Pandas中的GROUP BY AND SUM不丢失列)
Group by + New Column + Grab value former row based on conditionals(GROUP BY+新列+基于条件的前一行抓取值)
Groupby and interpolate in Pandas(PANDA中的Groupby算法和插值算法)
Pandas - Group Rows based on a column and replace NaN with non-null values(PANAS-基于列对行进行分组,并将NaN替换为非空值)
Grouping pandas DataFrame by 10 minute intervals(按10分钟间隔对 pandas 数据帧进行分组)