Search code examples
pythondjangocsvdjango-viewsexport-to-csv

Django Csv: Having trouble with writerow


This is basicly my code:

def export_to_excel(request):
    response = HttpResponse(content_type='text/csv')
    response['Content-Disposition'] = 'attachment; filename=responds.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

Everything looks ok, but when I really exported it there is something wrong:

excel

Everything in just a shell! Why? How so? What should I do?


Solution

  • The problem is Excel, just use Text to Columns feature and it will be fine. Or use LibreOffice Calc and it show the text import dialogue.