On Sep 5, 2017 6:28 AM, "Rakhee Menon" <menonrakhe...@gmail.com> wrote:

CODE:

class FormList(APIView):
def get(self, request, id):
import ipdb;ipdb.set_trace()
item_obj = ItemMaster.objects.get(id=id)
serializer = ItemMasterSerializer(forms,many=False)
return Response(serializer.data, content_type="application/json")
def get(self,request):
forms = ItemMaster.objects.all()
serializer=ItemMasterSerializer(forms,many=True)
return Response(serializer.data, content_type="application/json")



I get this error.django-got-an-unexpected-keyword-argument-id.
when i try to access a specific item..Please can anyone suggest how to
solve this bug using APIViews and not by using viewset  as there is lot of
customization in my API.


The issue arises because you are defining the get() method twice with
different signatures. The second definition of get() without the id
argument is the 'active' definition since it is defined last, and had no
idea what to do with the extra 'id' argument.

Python does not support function/method overloading like Java, because of
PEP 8 and keep it simple and DRY and everything else about the Python
philosophy. It also ultimately names for cleaner and more legible code.

Not sure what you mean by a lot of customization. This code is pretty
boiler plate and would be better served by using a generic viewset in DRF,
such as ReadOnlyModelViewset:

http://www.django-rest-framework.org/api-guide/viewsets/#readonlymodelviewset

-James

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2Be%2BciVCgC6vvzCvRxGuMoTzq7FW051WP5oSUAKdwD%3D%3DE66BqA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to