获得API方面的授权客户的请求?

时间:2016-02-23 10:37:05

标签: django python-2.7 api django-rest-framework

我需要从授权客户端获得响应,客户端有一个令牌来从API请求书籍,所以我的代码如下;

class BooksViewSet(viewsets.ModelViewSet):

    permission_classes = [TokenHasScope]
    required_scopes = ['books']

这里我需要知道要求哪些书籍进行查询并向客户返回一个响应,我该怎么知道?

1 个答案:

答案 0 :(得分:0)

你可以像这样覆盖get_queryset

class BooksViewSet(viewsets.ModelViewSet):

    permission_classes = [TokenHasScope]
    required_scopes = ['books']

    def get_queryset(self):
        # Replace this queryset with the books you want to query for.
        # You can use self.request to access parameters.
        return Book.objects.all()