1. 服务代码
文件:app.py
import requests
from flask import Flask, render_template
app = Flask(__name__)
@app.route('/')
def movieapp():
url = "http://movie-quotes-2.herokuapp.com/api/v1/quotes/random"
response = requests.get(url).json()
return render_template("index.html", film=response['film'], quote=response['content'])
if __name__ == '__main__':
app.run(debug=False, host='0.0.0.0')
2. WSGI 文件
文件:wsgi.py
from app import app
if __name__ == '__main__':
app.run()
2. 安装依赖&启动服务
yum install -y python38 procps
python3 -m venv /opt/venv
source /opt/venv/bin/activate
pip install flask SQLAlchemy==1.4.44 loguru gunicorn -i https://pypi.douban.com/simple/ --trusted-host pypi.douban.com
#python /root/workspace/dbservice.py
if [ -z "${LISTEN_POST}" ] ; then
LISTEN_POST=8080
fi
gunicorn --bind 0.0.0.0:${LISTEN_POST} wsgi:app
参考:https://kevalnagda.github.io/flask-app-with-wsgi-and-nginx