In the following code, if i change the file output format to output.csv the file gets automatically downloaded ,but if i change the format to output.txt the files gets displayed on the browser.How to auto download the output.txt file
Since csv file is getting downloaded what are the problem with txt file for the same code
def downloadcsv(request):
try:
response = {}
output = fq_name+"/"+ "output.txt"
os.system(cmd)
logger.debug(file_name)
response.update({'status':0,'message': 'Success','file_name' : output})
except Exception as e:
response['message'] = "Exception while processing request"
response['status'] = 2
logger.exception(e)
return HttpResponse(JsonResponse(response), content_type="application/json")
$.post("/reports/downloadcsv/", snddata,
function callbackHandler(data, textstatus)
{
if (data.status == 0)
{
document.location.href = data.file_name;
//document.getElementById('my_iframe').src = data.file_name;
}
else if (data.status == 1 || data.status == 2)
{
$('#loading').hide();
alert('Error while processing data');
}
$('#loading').hide();
},
"json"
);