Flask¶
What is Flask¶
Flask is a lightweight WSGI web application framework. It is designed to make getting started quick and easy, with the ability to scale up to complex applications.
WSGI = Web Server Gateway Interface
A specification for communication between a web server and a Python-based web application (such as Flask).
Install¶
% mkdir flask_test
% cd flask_test
% python3 -m venv .venv
% source .venv/bin/activate
(.venv) % pip install flask
To escape from venv
(.venv) % deactivate
Code¶
(.venv) % touch app.py
(.venv) % nano app.py
| app.py | |
|---|---|
1 2 3 4 5 6 7 8 9 10 | |
(.venv) % mkdir templates
(.venv) % touch templates/index.html
| index.html | |
|---|---|
1 2 3 4 5 6 7 8 9 10 11 | |
Run¶
(.venv) % python3 app.py
* Running on http://127.0.0.1:5000
Press CTRL+C to quit
* Restarting with stat
* Debugger is active!
* Debugger PIN: 950-322-917

Save a list of Python libraries¶
(.venv) % tree
.
├── app.py
└── templates
└── index.html
(.venv) % pip freeze > requirements.txt
(.venv) % tree
.
├── app.py
├── requirements.txt
└── templates
└── index.html
(.venv) % cat requirements.txt
| requirements.txt | |
|---|---|
1 2 3 4 5 6 7 | |
To work in the same evnironmant
pip install -r requirements.txt
HTML -> Python -> HTML¶
| templates/index.html | |
|---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | |
| app.py | |
|---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | |
