I have a view that returns an HttpResponse:
file_name = 'rel_acao_{}.xlsx'.format(dt.now().strftime("%Y%m%d"))
response = HttpResponse(content_type='application/vnd.ms-excel')
response['Content-Disposition'] = 'attachment; filename={}'.format(file_name)
writer = pd.ExcelWriter(response)
df_1.to_excel(writer, sheet_name='Sheet1')
df_2.to_excel(writer, sheet_name='Sheet2')
writer.save()
return response
These view is called with the following button:
<div>
<button id="btn_Export" type="button" onclick="sendReport()">
Export to Excel
</button>
</div>
which in turn, calls the following function:
// Dispatch
function sendReport(){
$.ajax({
url: "{% url 'report_action:report_action_csv' %}",
type: 'POST',
data: {
'followup': JSON.stringify(followup),
'report': JSON.stringify(report)
}
});
}
as seeing here, there is a file somewhere in this data limbo:
Why am I not able to download the file? What am I doing wrong?