title: Using StreamingHttpResponse with Django Rest Framework CSV
body: <p>I have a standard DRF web application that outputs CSV data for one of the routes. Rendering the entire CSV representation takes a while to do. The data set is quite large so I wanted to have a streaming HTTP response so the client doesn't time out.</p>
  
  <p>However using the example provided in <a href="https://github.com/mjumbewu/django-rest-framework-csv/blob/2ff49cff4b81827f3f450fd7d56827c9671c5140/rest_framework_csv/renderers.py#L197" rel="noreferrer">https://github.com/mjumbewu/django-rest-framework-csv/blob/2ff49cff4b81827f3f450fd7d56827c9671c5140/rest_framework_csv/renderers.py#L197</a> doesn't quite accomplish this. The data is still one large payload instead of being chunked and the client ends up waiting for a response before the bytes are received. </p>
  
  <p>The structure is similar to what follows:</p>
  
  <p><strong>models.py</strong></p>
  
  <pre><code>class Report(models.Model):
    count = models.PostiveIntegerField(blank=True)
    ...
  </code></pre>
  
  <p><strong>renderers.py</strong></p>
  
  <pre><code>class ReportCSVRenderer(CSVStreamingRenderer):
    header = ['count']
  </code></pre>
  
  <p><strong>serializers.py</strong></p>
  
  <pre><code>class ReportSerializer(serializers.ModelSerializer):
    count = fields.IntegerField()
  
    class Meta:
      model = Report
  </code></pre>
  
  <p><strong>views.py</strong></p>
  
  <pre><code>class ReportCSVView(generics.Viewset, mixins.ListModelMixin):
    def get_queryset(self):
      return Report.objects.all()
  
    def list(self, request, *args, **kwargs):
      queryset = self.get_queryset()
      data = ReportSerializer(queryset, many=True)
      renderer = ReportCSVRenderer()
  
      response = StreamingHttpResponse(renderer.render(data), content_type='text/csv')
      response['Content-Disposition'] = 'attachment; filename="f.csv"'
  
      return response
  </code></pre>
  
  <p><strong>NOTE:</strong> had to comment out or change some things.</p>
  
  <p>Thank you</p>