简体   繁体   中英

Retrieving Variable & Processing List from Tastypie URL

Let's say my override_urls is like so:

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.

How can I nab user__username for get_object_list to process? 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).

PS, is there anyway to make user__username into just username (for the sake of prettyness)?

The user_username argument is passed in kwargs through the dispatching process not in request.GET.

You probably would want to override the get_list method and process the additional argument inside it. If you do it that way you can name your argument whatever you want and process it the way you wish.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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