Reputation: 7249
AssertionError: Expected view blabla to be called with a URL keyword argument named "pk". Fix your URL conf, or set the .lookup_field
attribute on the view correctly.
# If you want to use object lookups other than pk, set 'lookup_field'
well I don't want use URL to set pk , I want use pk from query_params for example something like :
request.query_params.get('id', None)
so how setup lookup_field ?
SOLVED it is on update method that we can override pk value
class blabla(generics.CreateAPIView,
generics.ListAPIView,
generics.RetrieveAPIView,
generics.UpdateAPIView):
def update(self, request, pk = None):
log.debug("update pk= %s , data = %s" % (pk, str(request.data)))
pk = request.data.get('id')
self.kwargs['pk'] = request.data.get('id')
return super().update(request, pk)
Upvotes: 2
Views: 2126
Reputation: 4606
Your code doesn't work because you reference to request
object on class level, and it is doesn't exists: it is created on instance-level. But you don't need it at all, just make:
lookup_field = 'id'
Upvotes: 3