From Network Security Wiki
Revision as of 12:25, 14 June 2018 by Amanjosan2008 (talk | contribs) (→‎Opions)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search


Source: blog.miguelgrinberg.com


pip3 install flask

Hello World

from flask import Flask
app = Flask(__name__)

def hello_world():
   return 'Hello World’

if __name__ == '__main__':
  • Access the above app from:


  • All parameters are optional:
app.run(host, port, debug, options)


host: Hostname to listen on. Defaults to (localhost). Set to ‘’ to have server available externally
port: Defaults to 5000
debug: Defaults to false. If set to true, provides a debug information
options: To be forwarded to underlying Werkzeug server.
  • Enable Debugging:
app.debug = True
  • Access URL over network with custom port:
app.run(host = '',port=5005)

Uploader Project

Source: tutorialspoint.com

nano upload_test.py
from flask import Flask, render_template, request
from werkzeug import secure_filename
app = Flask(__name__)

def upload_file():
   return render_template('upload.html')
@app.route('/uploader', methods = ['GET', 'POST'])
def upload_file():
   if request.method == 'POST':
      f = request.files['file']
      return 'file uploaded successfully'
if __name__ == '__main__':
   app.run(debug = True, host = '')
mkdir templates && cd templates
nano upload.html
      <form action = "" method = "POST" 
         enctype = "multipart/form-data">
         <input type = "file" name = "file" />
         <input type = "submit"/>

File Structure:

├── templates
│   └── upload.html
└── upload_test.py

Run the application:

python3 upload_test.py

Access the application on below URL:


blog comments powered by Disqus