How to know action (HTTP method) type in DRF generic views?

Viewed 601

When using ViewSets you can do self.action and get to know whether you are currently handling a GET or POST and such. How do you do the same with generic views like ListCreateAPIView?

I want to return a different serializer context in get_serializer_context depending on the current HTTP method being called. How do I go about this?

1 Answers

use self.request.method

def get_serializer_context(self, *args, **kwargs):
    print(self.request.method)
    # rest of your code
Related