'Getting error while partial update data in drf

Hi Everyone i am creating api for partially update record, but getting error [patch() missing 1 required positional argument: 'id'], please help me out

views.py

class GmsGarageViewset(APIView):
    def patch(self,request,id):
        garage_data=GmsGarage.objects.get(id=id)
        serializer=GmsGarageSerializer(garage_data,data=request.data,partial=True)
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data)
        else:
            return Response(serializer.errors,status=HTTP_400_BAD_REQUEST)

urls.py

path('gms/garage/<int:pk>',GmsGarageViewset.as_view())

output error

TypeError: patch() missing 1 required positional argument: 'id'
ERROR "PATCH /api/gms/garage/1 HTTP/1.1" 500 19954


Solution 1:[1]

you need to replace the url

path('gms/garage/<int:pk>',GmsGarageViewset.as_view())

with

path('gms/garage/<int:id>/',GmsGarageViewset.as_view())

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Abdelrahman Moustafa