James,
Thanks for responding.
I have changed the view to:
class AddToUserProfile(generics.CreateAPIView):
permission_classes = (permissions.IsAuthenticatedOrReadOnly,IsOwnerOrReadOnly)
queryset = UserPrefs.objects.all()
serializer_class = UserPrefSerializer
lookup_field = 'pk'
def get(self, request, *args, **kwargs):
return HttpResponse('Hello world')
def post(self, request, *args, **kwargs):
#return self.get(request, *args, **kwargs)
self.object = self.get_object()
context = self.get_context_data(object=self.object)
return self.render_to_response(context)
def create(self, serializer):
serializer.save(owner=self.request.user)
I get an error: Expected view AddToUserProfile to be called with a URL keyword argument named "pk". Fix your URL conf, or set the `.lookup_field` attribute on the view correctly.
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/69f2dbec-06a4-4338-953f-39f1f38576c1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment