In Django Rest Framework 2.x you could access, for example, the "fields" query parameter in a serializer like this:
fields = self.context['request'].QUERY_PARAMS.get('fields')
That no longer works in DRF 3.0, but I can't find the change documented in the API except in general terms. It looks like it might be something like self.context.get('request')?????
but I can't figure it out.
How would you do it in DRF 3.0? I'm talking about accessing the query.params in the serializer rather than in the view.
thanks
John
this is it for DRF 3:
fields = self.context.get('request').query_params.get('fields')
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