title: Django Rest Framework: Use URL parameter in serializer
body: <p>My goal is to use a URL parameter as a variable in a function and output it in the serializer. But the following solution doesnt work. Anybody know why?</p>
  <p>The URL looks like this:
  <a href="http://127.0.0.1:8000/v1/water-bodies/?from=2013-02-17&amp;to=2013-02-18" rel="nofollow noreferrer">http://127.0.0.1:8000/v1/water-bodies/?from=2013-02-17&amp;to=2013-02-18</a></p>
  <p><strong>models.py</strong></p>
  <pre><code>class Application(models.Model):
      &quot;&quot;&quot;Database models for application information&quot;&quot;&quot;
  
      name = models.CharField(max_length=255)
      machine_name = models.SlugField(max_length=255, allow_unicode=True)
      description = models.TextField(blank=True, null=True)
      indice_to_use = models.ForeignKey('Indice', on_delete=models.PROTECT, blank=True, null=True)
  
      def __str__(self):
          return self.name
  </code></pre>
  <p><strong>views.py</strong></p>
  <pre><code>class DetailView(APIView):
      def get_serializer_context(self):
          context = super().get_serializer_context()
          context[&quot;date_from&quot;] = self.request.query_params.get(&quot;from&quot;, None)
          return context
  
      def get(self, request, machine_name):
          application = Application.objects.get(machine_name=machine_name)
          serializer = OsdSerializer(application)
  
          return Response({&quot;Everything you need to analyzing &quot;+application.name: serializer.data})
  </code></pre>
  <p><strong>serializer.py</strong></p>
  <pre><code>class OsdSerializer(serializers.ModelSerializer):
      bands = BandSerializer(source='indice_to_use.needed_bands', many=True)
      satellite = SatelliteSerializer(source='indice_to_use.satellite_to_use')
      indice = IndiceSerializer(source='indice_to_use')
  
      def get_alternate_name(self, obj):
          return self.context.get('date_from')
  
      class Meta:
          model = Application
          fields = ['machine_name', 'name', 'description', 'indice', 'satellite', 'bands', 'date_from', ]
  </code></pre>
  <p><a href="https://i.stack.imgur.com/tPIhJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tPIhJ.png" alt="enter image description here" /></a></p>
  <p><a href="https://i.stack.imgur.com/ttTi0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ttTi0.png" alt="enter image description here" /></a></p>