uWSGI加载home.html,但不启动应用程序。请参阅下面的错误消息。
我已经尝试过:
遵循本指南:https://vladikk.com/2013/09/12/serving-flask-with-nginx-on-ubuntu/
快速入门指南:https://uwsgi-docs.readthedocs.io/en/latest/WSGIquickstart.html#deploying-flask
通过运行
运行 python sousVideRestServer.py
仅运行 Flask 应用程序。这会加载应用程序,因此我确定 Flask 应用程序正常。
我没有使用 venv。
wsgi ini 文件:
[uwsgi]
#Define uwsgi settings
master = true
processes = 5
#Must define number of threads if app is threaded
threads = 4
#Change directory
chdir = /home/pi/Projects/sousVide/
#Flask file to run
wsgi-file = sousVideRestServer.py
#Most likely app
callable = app
#socket file's location - Can be any file
socket = /home/pi/Projects/sousVide/sousVideSock.sock
#permissions for the socket file
chmod-socket = 666
#Clean up
vacuum = true
die-on-term = true
#Log
#logto = /var/log/uwsgi/%n.log
#Start stats server
stats = 192.168.1.101:1717
Gist Link to complete Flask App 下面是通用 Flask 应用程序。
from flask import Flask, request, jsonify, abort, make_response, render_template
from apscheduler.schedulers.background import BackgroundScheduler
class RESTAnovaController(AnovaController):
TIMEOUT_HEARTBEAT = 20
def __init__(self, mac_address, connect=True, logger=None):
self.last_command_at = datetime.datetime.now()
app = Flask(__name__)
@app.errorhandler(404)
def timeout_atnot_found(error):
return make_response(jsonify({'error': 'Not found.'}), 404)
@app.route('/', methods=['GET', 'POST'])
@app.route('/home', methods=['GET', 'POST'])
def displayWebPage():
return render_template('home.html')
if __name__ == "__main__":
try:
# Setup logging
logging.basicConfig(level=logging.INFO)
handler = logging.StreamHandler(sys.stdout)
handler.setFormatter(formatter)
app.logger.addHandler(handler)
app.anova_controller = RESTAnovaController(ANOVA_MAC_ADDRESS, logger=app.logger)
print(app.anova_controller.read_temp())
app.run(host='192.168.1.101', port=5000, debug=False)
except BaseException as e:
print(e)
finally:
app.anova_controller.close()
错误:WSGI 应用程序 0(挂载点='')
最佳答案
在 uwsgi
下运行时,
if __name__ == "__main__":
条件不会为True
,因此该条件下的代码将不会运行。鉴于您所写的内容,我相当确定这可以解释您的困境。
关于python - uWSGI应用程序找不到挂载点,但加载了html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57518278/