创建venv
-
安装virtualenv
pip install virtualenv
-
配置venv
路径 /home/flask/venv_flask_dev ##开发环境
venv名称为 venv_flask_devcd /home/flask/ python3 -m venv venv_flask_dev
-
进入venv
source /home/flask/venv_flask_dev/bin/activate
退出venv
cd /home/flask/venv_flask_dev/bin/activate deactivate
-
安装flaskgunicorn
pip install flask pip install gunicorn
-
测试flask
touch /home/flask/venv_flask_dev/hello.py export FLASK_APP=hello.py vim hello.py
from flask import Flask app = Flask(__name__) @app.route('/') def hello_world(): return 'Hello, World!'
使用gunicorn启动wsgi
gunicorn --workers=3 hello:app -b 127.0.0.1:8080 Booting worker with pid: 3496 Booting worker with pid: 3497 Booting worker with pid: 3499 curl 127.0.0.1:8080 Hello, World!
静默运行
gunicorn --workers=3 hello:app -b 127.0.0.1:8080 -D