简体   繁体   English

从Tastypie URL检索变量和处理列表

[英]Retrieving Variable & Processing List from Tastypie URL

Let's say my override_urls is like so: 假设我的override_urls如下所示:

def override_urls(self):
    return [
        url(r"^(?P<resource_name>%s)/(?P<user__username>\w{4,30})%s$" % (self._meta.resource_name, trailing_slash()), self.wrap_view('dispatch_list'), name="api_dispatch_list"),
        ]

I'd like to do some custom processing owith user__username: I'd like to get all of a user's 'post' objects and combine it with everyone they follow's post objects. 我想使用user__username进行一些自定义处理:我想获取用户的所有“发布”对象,并将其与他们关注的每个发布对象组合。

How can I nab user__username for get_object_list to process? 如何获取user__username以处理get_object_list? I tried to get it from the request using request.GET.get('user__username') but that didn't seem to make sense (and didn't work). 我试图使用request.GET.get('user__username')从请求中获取它,但这似乎没有任何意义(并且不起作用)。

PS, is there anyway to make user__username into just username (for the sake of prettyness)? PS,是否有将user__username变成用户名(为了美观)?

The user_username argument is passed in kwargs through the dispatching process not in request.GET. user_username参数在kwargs中通过调度过程传递,而不是在request.GET中传递。

You probably would want to override the get_list method and process the additional argument inside it. 您可能想要覆盖get_list方法并处理其中的其他参数。 If you do it that way you can name your argument whatever you want and process it the way you wish. 如果以这种方式进行操作,则可以随心所欲地命名您的论据,并以自己希望的方式对其进行处理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM