In my Views.py, I try to download the csv file first to client side then only wish to redirect to another page.
Below was my code
def main(request):
...
...
url = '//file1.km.in.com/sd/recipe/' +"/"+ model + "_" + code + ".csv"
filename=model + "_" + code + ".csv"
download_csv(url,filename)
data = {"TableForm": TableForm, "devicelist": devicelist_1}
time.sleep(10)
return redirect('/ProductList/BetaTest', data)
def download_csv(url,filename):
csv = process_file(url)
response = HttpResponse(csv, content_type='text/csv')
response['Content-Disposition'] = 'attachment; filename='+filename
return response
def process_file(file_handle):
df = pd.read_csv(file_handle, index_col=False)
return df.to_csv(index=False)
However, download function didn't work but it directly redirect to BetaTest page.
I try to edit to below code, and now the download function is work but it cannot redirect to another page:
def main(request):
...
...
data = {"TableForm": TableForm, "devicelist": devicelist_1}
csv = process_file(url)
response = HttpResponse(csv, content_type='text/csv')
response['Content-Disposition'] = 'attachment; filename='+filename
return response
time.sleep(10)
return redirect('/ProductList/BetaTest', data)
Is there any ideas to overcome this issue?