Sunday, May 31, 2015

Re: django - class based view store post data


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):

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
To post to this group, send email to
Visit this group at
To view this discussion on the web visit
For more options, visit

No comments:

Post a Comment