dimanche 4 avril 2021

How to pass my `download response` to next `app.route` in flask python

I m currently deploy a machine learning model in web using flask python, Does anyone know how to pass my response.headers["Content-Disposition"] = "attachment; filename=result.csv"into next @app.route('/database_download/<filename>'), so I could download or retrieve back from download button in HTML page?

app.py

    new_data = pd.DataFrame(dicts).set_index("Month")
        ##df_predict = pd.DataFrame(transform, columns=["predicted value"])
        response = make_response(new_data.to_csv(index = True, encoding='utf8'))
        response.headers["Content-Disposition"] = "attachment; filename=result.csv"

        labels = [d['Month'] for d in dicts]
            
        values = [d['Predictions'] for d in dicts]

        colors = [ "#F7464A", "#46BFBD", "#FDB45C", "#FEDCBA",
                       "#ABCDEF", "#DDDDDD", "#ABCABC", "#4169E1",
                       "#C71585", "#FF4500", "#FEDCBA", "#46BFBD"]

        line_labels=labels
        line_values=values
        return render_template('graph.html', title='Time Series Sales forecasting', max=17000, 
        labels=line_labels, values=line_values)


        
        ##response = make_response(new_data.to_csv(index = True, encoding='utf8'))
        ##response.headers["Content-Disposition"] = "attachment; filename=result.csv"
        ##return response

@app.route('/database_download/<filename>')
def database_download(filename):
return send_from_directory('database_reports', filename)



Aucun commentaire:

Enregistrer un commentaire