python - read a existing csv file in flask and then download it through browser -


i have existing csv file downloaded server desktop using python script. want modify code, or write new 1 download same csv file when user access link in browser. how using flask ?

import os import csv flask import flask, make_response app = flask(__name__) w_open=open(filename,'r') @app.route('/csv/')   def download_csv():      csv = w_open      response = make_response(csv)     cd = 'attachment; filename=rosterunified.csv'     response.headers['content-disposition'] = cd      response.mimetype='text/csv'      return response  if __name__=='__main__':    app.run() 


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -