StreamingHttpResponse for Large Data

Send large files or CSVs without loading into memory.


# models.py

from django.db import models

class Record(models.Model):
    title = models.CharField(max_length=120)
  

# admin.py

from django.contrib import admin
from .models import Record

@admin.register(Record)
class RecordAdmin(admin.ModelAdmin):
    list_display = ("title",)
  

# views.py
import csv
from django.http import StreamingHttpResponse
def big_csv(request):
    def rows():
        yield "title\n"
        for i in range(1000000):
            yield f"row-{i}\n"
    response = StreamingHttpResponse(rows(), content_type="text/csv")
    response['Content-Disposition'] = 'attachment; filename="big.csv"'
    return response
  
Explanation:
  • Use a generator to yield chunks progressively.
  • Great for very large CSVs or logs.
  • Category Views (FBV & CBV)
  • Total Views 872
  • Last Modified 05 January, 2026
  • Tags #streaming #response #performance #views
Never miss a story on Django.wiki

Subscribe for fresh tutorials, snippets, and updates.

By subscribing you agree to our Privacy Policy.