[Answered ]-With Django REST framework, how do I parse a RESTful string parameter?

0👍

To use the path params added in the url pattern, you must add the **kwargs as an extra parameter to the get() method. Your view should look like this:

class UserView(APIView):
    def get(self, request, **kwargs):
       ...
       author = kwargs.get('author', None)

1👍

get() method should accept url parameters too, you can use *args and **kwargs syntax to make sure it works no matter how you name your parameter:

class UserView(APIView):
    def get(self, request, *args, **kwargs):
        ...
        author = self.kwargs.get('author', None)

Leave a comment