我想创建两个端点/comments/
和{
现在,我的观点是
class CommentsListview(APIView):
serializer_class = CommentSerializer
def get(self, request, format=None):
comments, _, _, = Comments.get_comment_users(request.user)
comments_serializer = CommentSerializer(comments, many=True)
return Response({'comments': comments_serializer.data})
def requests(sel,f request, format=None):
_, requests, _ = Comments.get_comment_users(request.user)
requests_serializer = CommentSerializer(requests, many=True)
return Response({'requests': requests_serializer.data})
我想允许用户转到localhost:8000/comments/
查看他们的评论,localhost:8000/comments/requests/
来查看他们的未决评论请求。因为我还没有弄清楚这个问题,唯一的解决方案是要求用户使用参数作为标志/comments/?requests=True
来切换端点的行为,但这看起来太草率了。在
路由和使用集合
/comments/
将调用list
方法/comments/requests/
将调用requests
方法另请看GenericViews和{a2}文档,这可能会有帮助
相关问题 更多 >
编程相关推荐