Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamically set renderer_class in DRF

How can i dynamically set the renderer_class in DRF from a request query parameter?

I know that DRF chooses the renderer_class based on ACCEPT header but the client has requested an option to select the class based on GET query parameter

like image 825
James Bingo Avatar asked Sep 12 '25 22:09

James Bingo


1 Answers

This can be achieved by overwriting the get_format_suffix function on a view.

class MyView(APIView):

    format_suffix = 'format'

    def get_format_suffix(self, **kwargs):
        return self.request.query_params.get(self.format_suffix)
like image 132
James Bingo Avatar answered Sep 16 '25 00:09

James Bingo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!