在Tastypie中获取请求参数 [英] get request parameters in Tastypie

查看:171
本文介绍了在Tastypie中获取请求参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为使用Tastypie的NoSQL数据库(Neo4j)的应用程序构建一个REST API。

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传递一个参数到这个方法(像$ code> http://127.0.0.1:8000/api/机场/?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.

问题是请求是所以我不能得到它的参数!

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: '{}'>}

感谢您的帮助

推荐答案

目前位置参数请求不传递到 obj_get_list

Currently positional argument request is not passed toobj_get_list.

所以你应该: / p>

So you should:

def obj_get_list(self, bundle, **kwargs):

    param =  bundle.request.GET['param']
    #fetch objects based on param
    return objects

这篇关于在Tastypie中获取请求参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆