Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you access query params in a Django Rest Framework 3.0 serializer?

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

like image 484
John Avatar asked Feb 22 '15 02:02

John


1 Answers

this is it for DRF 3:

fields = self.context.get('request').query_params.get('fields')
like image 168
John Avatar answered Oct 19 '22 21:10

John