I am trying to display some csv(comma seperated values) in my project. So I have a html button click upon which a django view function is called through JavaScript. This is my django view function :
def make_csv(request):
testdata = "[{\"severity\":\"0\",\"description\":\"USB Connected\",\"date\":\"01/01/2015\",\"time\":\"11:35:20\"},{\"severity\":\"3\",\"description\":\"USB Disconnected\",\"date\":\"01/01/2015\",\"time\":\"10:30:19\"}]";
data = json.loads(testdata)
response = HttpResponse(content_type='text/csv')
response['Content-Disposition'] = 'attachment; filename="eventlog.csv"'
writer = csv.writer(response,csv.excel)
writer.writerow(data[0].keys())
for row in data:
writer.writerow(row.values())
return response
But I can't get any file displayed in my browser. Also I can see the values returned using my JavaScript. Is there a way to display the result as a seperate file in the browser so that users can download it?