Help me to Generate CSV through Django View from database - and download the same

19 views
Skip to first unread message

Shareef 617

unread,
Oct 16, 2018, 3:39:46 AM10/16/18
to Django users
Help me to Generate CSV through Django View from database - and download the same 

mottaz hejaze

unread,
Oct 16, 2018, 6:57:33 AM10/16/18
to django...@googlegroups.com
import csv
from django.http import HttpResponse

def some_view(request):
    # Create the HttpResponse object with the appropriate CSV header.
    response = HttpResponse(content_type='text/csv')
    response['Content-Disposition'] = 'attachment; filename="somefilename.csv"'

    writer = csv.writer(response)
    writer.writerow(['First row', 'Foo', 'Bar', 'Baz'])
    writer.writerow(['Second row', 'A', 'B', 'C', '"Testing"', "Here's a quote"])

    return response

On Tue, Oct 16, 2018 at 9:39 AM Shareef 617 <share...@gmail.com> wrote:
Help me to Generate CSV through Django View from database - and download the same 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/d3faf615-5b41-4c5d-ad45-d233e1dbd62a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Mohammad Shareef M

unread,
Oct 16, 2018, 8:09:02 AM10/16/18
to django...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages