Skip to content

Instantly share code, notes, and snippets.

Avatar

Erik Lopez niuware

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

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