python venv flask gunicorn 部署与 pycharm 连接

创建venv

  1. 安装virtualenv
    pip install virtualenv

  2. 配置venv

    路径 /home/flask/venv_flask_dev ##开发环境
    venv名称为 venv_flask_dev

    cd /home/flask/
    python3 -m venv venv_flask_dev
    
  3. 进入venv

    source /home/flask/venv_flask_dev/bin/activate
    

    退出venv

    cd /home/flask/venv_flask_dev/bin/activate
    deactivate
    
  4. 安装flask\gunicorn

    pip install flask
    pip install gunicorn
    
  5. 测试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
    

posted on 2021-02-07 14:45  BionExit  阅读(287)  评论(0编辑  收藏  举报

导航