python - Writing to csv file via django is adding the module name in the first cell of the file header -
i trying write csv file django given list of headers , various data. file being created 1 exception, first cell showing module info right before value of header , i'm not sure why. read documentation related csv file outputting , modeled code after indicated below:
file_name = '%s_success.csv' % file_name response = httpresponse(csv, content_type='text/csv') response['content-disposition'] = 'attachment; filename=%s' % file_name c = csv.writer(response) headers = ['foo', 'bar', 'abc', '123'] c.writeheader(headers) row in data: ... ...
result:
<module 'csv' '/usr/local/lib/python2.7/csv.pyc'>foo, bar, abc, 123
i want:
foo, bar, abc, 123
what should change?
it looks you're including module in response:
response = httpresponse(csv, content_type='text/csv')
just try
response = httpresponse(content_type='text/csv')
Comments
Post a Comment