8👍
✅
I agree with @jorilallo’ comments about using request.data
inside get
function.
Alternatively, what you could do is create another function in the view which can have either request.data
or request.query_params
as arguments:
class UpdateUser(APIView):
permission_classes = (permissions.IsAuthenticated,)
def post(self, request, *args, **kwargs):
# POST have request.data
return self.process_request(request, request.data)
def get(self, request, format=None):
# GET have request.query_params
return self.process_request(request, request.query_params)
def process_request(self, request, data):
# Do stuff here with data
# return a response
Here, process_request
function is called from both post
and get
methods and relevant data
is passed as arguments.
👤AKS
Source:stackexchange.com