[Django]-Rest-framework "get() missing 1 required positional argument"

2👍

When you are adding params to your url, you have to add an extra param to your method definition, like this:

# urls.py
url(r'^questions/(?P<pk>[\w:|-]+)/$', TheView.as_view(), name='view')

In the url above, you are passing a url param (pk) so you have to receive it in the method:

# views.py
class TheView(APIView):
   def get(self, request, pk):
     ...

But in your case, you want to pass data by query params.

# urls.py
url(r'^questions/$', TheView.as_view(), name='view')

so you don’t have to receive it in the method declaration, use:

def get(self, request):
pk = request.GET.get('pk')

instead.

👤arcegk

Leave a comment