how to convert query list into csv using django thaks before
+3
A:
Here's one simple way:
from django.http import HttpResponse
import csv
response = HttpResponse (content_type='text/csv')
writer = csv.writer(response)
# now you can use writer.writerows() to write comma separated values to your response object, for example:
from django.contrib.auth.models import User
writer.writerows(User.objects.values_list('id','username','date_joined'))
# return the response object:
return response
Ofri Raviv
2010-01-04 09:09:13
+1
A:
You can just write a template which outputs comma-separated values. It's pretty straightforward. For instance if foo_list is in the context:
{% for foo in foo_list %}"{{ foo.stuff }}","{{ foo.more_stuff }}"
{% endfor %}
ozan
2010-01-04 10:28:30