I just create a web application that can generate an excel file using XLSXWRITER. It can download the file using send_file command using python. But the problem is whenever i download the file sometimes a rare error occurred like it download the previous file that i download before , when you check the file it should be the new one. I dont know if it on cache problem or not.
What i already test :
Using 2 device to check the file. When error occurred on 1 device i download it on another device and it work.
Clear browser data and cache (not solve anything)
restart internet and pc and even python passenger (not solve anything)
=================================================================
Im using python for my backend and xlsxwriter to write the excel file.
This is what the download work :
When you click the download button
=> it create an xlsx file and write the data on it after that
=> it save the xlsx on the server folder
=> redirect into route that do send file of the excel into download stream using send_file
=>get the download file from the server.
All happened on the 1 click
Code python for the process :
@__app.route('/report', methods=['GET','POST'])
@is_logged_in
def report():
if request.method == 'POST':
if request.form['action'] == 'DownloadReport':
__CustomerName_AddReport_Form = request.form['CustomerNametxt']
__Tax_AddReport_Form = request.form['Taxtxt']
__Bulan_AddReport_Form = request.form['Bulantxt']
__Tahun_AddReport_Form = request.form['Tahuntxt']
if __CustomerName_AddReport_Form:
workbook = xlsxwriter.Workbook('Report.xlsx')
worksheet = workbook.add_worksheet()
worksheet.write('B2','ANYTHING')
workbook.close()
return render_template('downloadreport.html')
else:
return render_template('report.html')
@__app.route('/downloadreport', methods=['GET'])
def downloadreport():
return send_file('/home/suiinkxy/jakarta/Report.xlsx' ,as_attachment=True)
Anyone can help with this , anything can do i would appreciate criticism and opinion if it can make me better. Thank you before.
Update Information :
Whenever the file is downloading the fresh one the network response is status code : 200 OK, But everytime it failed the response (download the previous version) it changed into [Status Code : 200 OK (From disk cache) ]. Any solution to disable it ? *I am using flask for my python and html for frontend.
Update Informatin (1) :
I found the problem , its all about caching on the browser. If i use disable cache on chrome everything is fine or using always refresh from edge. The problem is how to disable caching from my python or from my browser (chrome or edge) forever and not only on developer option(f12) .