Skip to content

Instantly share code, notes, and snippets.

@jonperron
Last active November 30, 2023 17:29
Show Gist options
  • Star 24 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jonperron/733c3ead188f72f0a8a6f39e3d89295d to your computer and use it in GitHub Desktop.
Save jonperron/733c3ead188f72f0a8a6f39e3d89295d to your computer and use it in GitHub Desktop.
Serve pandas dataframe as csv with Django
from django.http import HttpResponse
import pandas as pd
def foo():
results = pd.Dataframe()
response = HttpResponse(content_type='text/csv')
response['Content-Disposition'] = 'attachment; filename=filename.csv'
results.to_csv(path_or_buf=response,sep=';',float_format='%.2f',index=False,decimal=",")
return response
@georgmzimmer
Copy link

perfect

@kadiagdg
Copy link

kadiagdg commented Dec 1, 2021

thank you so much !

@HOLL4ND
Copy link

HOLL4ND commented Mar 31, 2022

nice

@PingoLee
Copy link

Perfect

@harshavardhannarla
Copy link

Thank you

@Muhammadb1094
Copy link

That's good, worked in just 1st try.. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment