I've got an ajax call to a flask route. This ajax call is inside an onlick function of a button (because I have to send some preprocessed data). In the python code,I create a xlsx spreadhseet with 2 tabs and save the file in the server. Then I am trying to download it in the client but without success. No errors, and the response is 200 OK, but the file is not downloaded. This is my python code:
@app.route('/download_file', methods=['GET', 'POST'])
def download_file():
v1 = request.json['v1']
v2 = request.json['v2']
v1_df = pd.DataFrame(v1, columns=V1_HEADERS)
v2_df = pd.DataFrame(v2, columns=V2_HEADERS)
final_excel = f'resources/final_excel.xlsx'
writer = pd.ExcelWriter(final_excel, engine='xlsxwriter')
v1_df.to_excel(writer, sheet_name='V1', index=False)
v2_df.to_excel(writer, sheet_name='V2', index=False)
writer.save()
return send_file(final_excel, as_attachment=True, mimetype='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
I also tried send_directory
without success.
What am I doing wrong? I'm a little desperate.
Thank you very much in advance.