15
votes

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

1

1 Answers

28
votes

this is it for DRF 3:

fields = self.context.get('request').query_params.get('fields')