TODO

What is flask?

  • Python web application framework.

Why flask?

  • lightweight
  • ability to scale up.

How to use basic functionality of flask?

Install and activation

1
2
3
4
$ mkdir myproject
$ cd myproject
$ python3 -m venv venv
$ . venv/bin/activate
1
2
PS C:\path\to\app> py -m venv venv
PS C:\path\to\app> venv\Scripts\activate

Real code example

1
2
3
4
5
6
from flask import Flask
app = Flask(__name__)

@app.route('/')
def hello_world():
return 'Hello, World!'

Run code

1
$ export FLASK_APP=hello.py
1
PS C:\path\to\app> $env:FLASK_APP = "hello.py"

Then flask run or python -m flask run.

Any helpful points?

  • Make sure to not call your application flask.py because this would conflict with Flask itself.
  • If you have the debugger disabled or trust the users on your network, you can make the server publicly available simply by adding --host=0.0.0.0 to the command line.

Reference material.