在 API 端获取授权客户端的请求



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

class BooksViewSet(viewsets.ModelViewSet):
    permission_classes = [TokenHasScope]
    required_scopes = ['books']

在这里我需要知道哪些书被要求进行查询并向客户端返回响应,我该如何弄清楚?

你可以像这样覆盖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()

最新更新