I have a DataFrame generated from a database. How do I provide a response wherein it downloads a CSV?
Basically,
df = magic_dataframe_supplier()
response = HttpResponse(content_type='text/csv')
response['Content-Disposition'] = 'attachment; filename=export.csv'
# ... type mapping code ...
return response
I've got a working version with csv.writer
but for obvious reasons, that is not a DataFrame
. And I'm unclear on how exactly I can turn a df
into such an object.