喜做這個請求時:組/ 25010a31-fc5b-47c8-9c5c-d740e5743f52// 4 /成員 - 我碰到一個「細節」:「未找到」Django Rest Framework - 「detail」:「未找到。」
但是,如果你在查詢集看我已經印刷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
@Ivan'過濾器結果與相同的問題 – Danny
請張貼您的網址。 –