嗨,在执行这个请求时:groups/25010a31-fc5b-47c8-9c5c-d740e5743f52/members/4/ - 我收到 "detail": "Not found" 的回复。
但是,如果您查看我打印的 Groupmember 实例的查询集,这将打印出该特定实例,因此显然它存在?
视图:
class MemberDetail(mixins.RetrieveModelMixin,
mixins.DestroyModelMixin,
mixins.UpdateModelMixin,
generics.GenericAPIView):
serializer_class = GroupMembersSerializer
lookup_field = "user_id"
lookup_url_kwarg = "uuid"
def get_queryset(self):
group = self.kwargs["uuid"]
user_id = self.kwargs["user_id"]
print GroupMember.objects.get(group = group, user_id = user_id)
return GroupMember.objects.get(group = group, user_id = user_id)
def get(self, request, *args, **kwargs):
return self.retrieve(self, request, *args, **kwargs)
def put(self, request, *args, **kwargs):
return self.update(self, request, *args, **kwargs)
def delete(self, request, *args, **kwargs):
return self.destroy(self, request, *args, **kwargs)
网址:
urlpatterns = [
url(r'^$', views.GroupList.as_view()),
url(r'^(?P<uuid>[^/]+)/$', views.GroupDetail.as_view()),
url(r'^(?P<uuid>[^/]+)/members/$', views.MemberList.as_view()),
url(r'^(?P<uuid>[^/]+)/members/(?P<user_id>[0-9]+)/$', views.MemberDetail.as_view()),
]
需要帮忙吗?
get_queryset
返回单个对象而不是查询集。我认为你应该使用filter
而不是get
。 - Ivan"group"
(通常是类似于r'^group/(?P<uuid>[^/]+)
这样的内容)。通常路由器会寻找"group-detail"
,但没有找到。我有什么遗漏吗? - Ivan