Skip to content

Instantly share code, notes, and snippets.

View Abdurahman-hassan's full-sized avatar
👨‍💻

Abdelrahman hassan hamdy Abdurahman-hassan

👨‍💻
View GitHub Profile
@Abdurahman-hassan
Abdurahman-hassan / django_stream_queryset_to_csv.md
Created November 14, 2022 00:50 — 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