FLASK学习记录-第一个Flask程序
$ pip install flask -i https://pypi.tuna.tsinghua.edu.cn/simple Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple Collecting flask Downloading https://pypi.tuna.tsinghua.edu.cn/packages/93/a6/aa98bfe0eb9b8b15d36cdfd03c8ca86a03968a87f27ce224fb4f766acb23/flask-3.0.2-py3-none-any.whl (101 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 101.3/101.3 kB 1.2 MB/s eta 0:00:00 Collecting Werkzeug>=3.0.0 (from flask) Downloading https://pypi.tuna.tsinghua.edu.cn/packages/c3/fc/254c3e9b5feb89ff5b9076a23218dafbc99c96ac5941e900b71206e6313b/werkzeug-3.0.1-py3-none-any.whl (226 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 226.7/226.7 kB 3.9 MB/s eta 0:00:00 Collecting Jinja2>=3.1.2 (from flask) Downloading https://pypi.tuna.tsinghua.edu.cn/packages/30/6d/6de6be2d02603ab56e72997708809e8a5b0fbfee080735109b40a3564843/Jinja2-3.1.3-py3-none-any.whl (133 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 133.2/133.2 kB 10.1 MB/s eta 0:00:00 Collecting itsdangerous>=2.1.2 (from flask) Downloading https://pypi.tuna.tsinghua.edu.cn/packages/68/5f/447e04e828f47465eeab35b5d408b7ebaaaee207f48b7136c5a7267a30ae/itsdangerous-2.1.2-py3-none-any.whl (15 kB) Collecting click>=8.1.3 (from flask) Downloading https://pypi.tuna.tsinghua.edu.cn/packages/00/2e/d53fa4befbf2cfa713304affc7ca780ce4fc1fd8710527771b58311a3229/click-8.1.7-py3-none-any.whl (97 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 97.9/97.9 kB 10.6 MB/s eta 0:00:00 Collecting blinker>=1.6.2 (from flask) Downloading https://pypi.tuna.tsinghua.edu.cn/packages/fa/2a/7f3714cbc6356a0efec525ce7a0613d581072ed6eb53eb7b9754f33db807/blinker-1.7.0-py3-none-any.whl (13 kB) Collecting importlib-metadata>=3.6.0 (from flask) Downloading https://pypi.tuna.tsinghua.edu.cn/packages/2d/0a/679461c511447ffaf176567d5c496d1de27cbe34a87df6677d7171b2fbd4/importlib_metadata-7.1.0-py3-none-any.whl (24 kB) Collecting zipp>=0.5 (from importlib-metadata>=3.6.0->flask) Downloading https://pypi.tuna.tsinghua.edu.cn/packages/c2/0a/ba9d0ee9536d3ef73a3448e931776e658b36f128d344e175bc32b092a8bf/zipp-3.18.1-py3-none-any.whl (8.2 kB) Collecting MarkupSafe>=2.0 (from Jinja2>=3.1.2->flask) Downloading https://pypi.tuna.tsinghua.edu.cn/packages/5f/5a/360da85076688755ea0cceb92472923086993e86b5613bbae9fbc14136b0/MarkupSafe-2.1.5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (25 kB) Installing collected packages: zipp, MarkupSafe, itsdangerous, click, blinker, Werkzeug, Jinja2, importlib-metadata, flask Successfully installed Jinja2-3.1.3 MarkupSafe-2.1.5 Werkzeug-3.0.1 blinker-1.7.0 click-8.1.7 flask-3.0.2 importlib-metadata-7.1.0 itsdangerous-2.1.2 zipp-3.18.1
编写第一个Flask程序
(flask-test1) [ flask-test1]$ vi app.py from flask import Flask app=Flask(__name__) @app.route("/") def index(): return "This is index page" if __name__=='__main__': app.run(host='0.0.0.0',port=8000,debug=True) 后台运行 (flask-test1) [dog@iZfkm309huj7srZ flask-test1]$ nohup python app.py & 查看日志 (flask-test1) [dog@iZfkm309huj7srZ flask-test1]$ tail -f nohup.out * Serving Flask app 'app' * 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 all addresses (0.0.0.0) * Running on http://127.0.0.1:8000 * Running on http://xxx:8000 Press CTRL+C to quit * Restarting with stat * Debugger is active! * Debugger PIN: 108-859-976 183.238.113.222 - - [28/Mar/2024 12:40:18] "GET / HTTP/1.1" 200 -