Skip to content

Instantly share code, notes, and snippets.

View ian117's full-sized avatar
🏠
Working from home

IanVss ian117

🏠
Working from home
View GitHub Profile
@ian117
ian117 / django_stream_queryset_to_csv.md
Created March 11, 2022 06:08 — forked from niuware/django_stream_queryset_to_csv.md
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