Skip to content

Instantly share code, notes, and snippets.

View niuware's full-sized avatar

Erik Lopez niuware

  • Tokyo
View GitHub Profile
@niuware
niuware / django_stream_queryset_to_csv.md
Created October 18, 2019 03:41
How to stream a CSV file from a large QuerySet using Django's StreamingHttpResponse

Stream a CSV file from a QuerySet using StreamingHttpResponse

This is a sample on how to stream the results of a large QuerySet into a CSV file using Django StreamingHttpResponse class.

  1. Add the CSVStream class in your project, for example a writers.py file:
import csv
from django.http import StreamingHttpResponse