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
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With