Python Forum
Flask generating a file for download
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Flask generating a file for download
#1
Hi
Im new att flask. Im trying to port an desktop app i made to the web so im using flask to do it.
Well what im trying to do is to generate a file with a list of data typed in a form in the html and then make it available for download and later on the file gets removed.

here is my code so far

@app.route('/result',methods = ['POST', 'GET'])
def result():
   if request.method == 'POST':
      cablename = request.form['cablename']
      parts = int(request.form['parts'])
      result = request.form
      print('{}.{}'.format(cablename, parts))

      for part in range(parts):
          print('{}.{}'.format(cablename, part+1))
          file1.writelines('{}.{}\n'.format(cablename, part+1))
          file1.flush()
          
      return render_template("result.html",result = result)
This code makes a file with a list of the data but i dont know how to make it available for download and im not sure if its the best way to do it.

So my questions are there a better way to do it maybe buffer all the data before generate the file with it for download and after download it gets removed.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  show csv file in flask template.html rr28rizal 8 34,793 Apr-12-2021, 09:24 AM
Last Post: adamabusamra
  Login and download an exported csv file within a ribbon/button in a website Alekhya 0 2,669 Feb-26-2021, 04:15 PM
Last Post: Alekhya
  flask How to output stderr and exceptions to log file umen 4 4,812 Jun-20-2020, 06:11 AM
Last Post: umen
  Cannot download latest version of a file TheTechRobo 3 2,303 May-20-2020, 08:33 PM
Last Post: TheTechRobo
  Read owl file using python flask Gayathri 1 2,458 Nov-20-2019, 12:56 PM
Last Post: ChislaineWijdeven
  Create .exe file for Python flask website. vintysaw 4 19,282 Nov-18-2019, 07:56 AM
Last Post: tonycstech
  download pdf file from website m_annur2001 1 3,011 Jun-21-2019, 05:03 AM
Last Post: j.crater
  [Flask] Uploading CSV file to flask, only first line being uploaded. Help ! KirkmanJ 2 6,807 Jun-25-2018, 02:24 PM
Last Post: KirkmanJ
  How to perform predictions on a data in csv file using Flask? manjusavanth 0 4,528 May-23-2018, 09:03 AM
Last Post: manjusavanth
  I Want To Download Many Files Of Same File Extension With Either Wget Or Python, eddywinch82 15 14,550 May-20-2018, 06:05 PM
Last Post: eddywinch82

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020