Download zip file using python flash web page

  1. Install basic requirements.

    pip install flask

  2. Create python file download.py will server the basic web page with clickable button.

    from flask import Flask, send_file app = Flask(name) @app.route('/') def index(): return ''' <html> <body> <h1>Download Text File</h1> <a href="/download"><button>Download</button></a> </body> </html> ''' @app.route('/download') def download_file(): return send_file('myZfile.zip', as_attachment=True) if name == 'main': app.run(debug=True)

  3. Create a valid zip file "myZfile.zip" in same folder.

  4. Run the python in command prompt

python download.py

python will start web server and listen in port 5000 as shown below.

  • Serving Flask app 'download'
  • Debug mode: on WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
  • Running on http://127.0.0.1:5000 Press CTRL+C to quit
  • Restarting with stat
  • Debugger is active!
  • Debugger PIN: 263-856-509

Web page is accessible in browser with URL: "http://127.0.0.1:5000"

Facebook Facebook Twitter Reddit

Leave a Reply