[英]Flask deployment using twistd
In the flask doco the following description is shown of deploying a flask app under twistd. 在flask doco中 ,显示了在扭曲状态下部署flask应用程序的以下描述。
twistd web --wsgi myproject.app
I have a foo.py which looks like this 我有一个看起来像这样的foo.py
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello, World!'
if __name__ == "__main__":
app.run(host="0.0.0.0", port=8080)
So I expected to be able to run that under twistd like this 所以我希望能够在这样的扭曲下运行
twistd web --wsgi foo.app
but twistd doesn't like that (just spits out the help text). 但不喜欢这种方式(只是吐出帮助文本)。
What am I doing wrong ? 我究竟做错了什么 ?
BTW in case it matters I'm running this in a virtualenv (in which I have installed both flask and twisted) and the current directory when I issue the twistd command contains foo.py . 顺便说一句,万一有问题,我在virtualenv(我已经安装了flask和twisted)中运行它,并且当我发出twisted命令时,当前目录包含foo.py。
EDIT : The version of twistd I am using is 18.7.0 编辑 :我使用的扭曲版本是18.7.0
I had failed to notice (until prompted to by Peter Gibson's comment ) that after the help text appears the message "No such WSGI application: 'foo.app'" appears. 我没有注意到(直到Peter Gibson的评论提示),在帮助文本出现之后,出现消息“没有这样的WSGI应用程序:'foo.app'”。
You need to add the current directory to the PYTHONPATH environment variable. 您需要将当前目录添加到PYTHONPATH环境变量。 Try
尝试
PYTHONPATH=. twistd web --wsgi foo.app
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.