我试图从我的html页面发帖,得到以下错误。
但是它在PostMan中运行得很好generics.GenerivAPIView.But得到的错误
AssertionError: Expected view OrganisationListView to be called with a URL keyword argument named "id". Fix your URL conf, or set the `.lookup_field` attribute on the view correctly.
[10/Jul/2018 08:30:09] "OPTIONS /api/client/Organisation/ HTTP/1.1" 500 14720
class OrganisationListView(generics.GenericAPIView,
mixins.ListModelMixin,
mixins.CreateModelMixin,
mixins.UpdateModelMixin,
mixins.RetrieveModelMixin,
mixins.DestroyModelMixin):
serializer_class = OrganisationSerilizer
Organisation.objects.get(id=self.request.Organisation.id)
queryset = Organisation.objects.all()
# allowed_methods = ('GET', 'POST', 'PUT', 'HEAD', 'DELETE')
filter_backends = (DjangoFilterBackend,OrderingFilter, SearchFilter)
filter_class = OrganisationFilter
ordering_fields = ('name','active')
search_fields = ('name',)
# for key
lookup_field = 'id'
def get(self, request, id=None):
if id:
print("get called with")
return self.retrieve(request, id)
else:
print("get called without ID")
return self.list(request)
def post(self, request, *args, **kwargs):
# queryset = self.filter_queryset(self.get_queryset())
print(request.data)
print("Hello")
return self.create(request, *args, **kwargs)
def perform_create(self, serializer):
serializer.save()
def put(self, request, id=None):
return self.update(request, id)
def delete(self,request,id=None):
print(request.data)
print(id)
return self.destroy(request,id)