使用uwsgi和flask-script Manager部署flask应用程序 [英] deploying flask app with uwsgi and flask-script Manager
问题描述
mydirectory / uwsgi_application.ini
...
#python模块导入
app = run_web
module =%(app)
callable = app
...
,
mydirectory /run_web.py
from ersapp import app $ b $ if if __name__ ==__main__:
app.run()
,
mydirectory / ersapp / __ init__.py
.. 。
app = Flask('ersapp')
...
但是现在,我正在关注Miguel Grinberg的Flask book,在这里他使用了一个如下所示的应用程序工厂:
$ b
mydirectory / ersapp / __ init__.py
...
def create_app(config_name):
webapp = Flask(__ name__)
...
return webapp
带有管理员(参见
) webapp import create_app mydirectory / manage.py
从 $ rel =nofollow> flask-script Manager
...
webapp = create_app(''FLASK_CONFIG'''or'default')
manager = Manager(webapp)
...
if __name__ =='__main__':
manager.run()
配置,我用 $ python manage.py runserver
触发我的开发服务器,而之前我用 $ python run_web.py
现在,我正在努力在uwsgi配置文件中放置什么来允许此应用程序通过UWSGI部署。具体而言,应用程序
,模块
和可调用
变量。
我在日志中遇到的错误是:
。 ..
---找不到python应用程序,检查你的启动日志是否有错误---
...
我也使用 flask-script
管理器,所以我做的是
-
创建了一个
wsgi.py
。 b
$ b从应用导入*
application = create_app(development) -
然后
uwsgi --wsgi-file wsgi.py - 可调用的应用程序
$ b
注意:callable是 wsgi.py
中的烧瓶对象名称。
Traditionally, I have configured the UWSGI configuration file to call an application like below:
mydirectory/uwsgi_application.ini
...
#python module to import
app = run_web
module = %(app)
callable = app
...
,
mydirectory/run_web.py
from ersapp import app
if __name__ == "__main__":
app.run()
,
mydirectory/ersapp/__init__.py
...
app = Flask('ersapp')
...
But now, I am following Miguel Grinberg's Flask book and here he uses an application factory like below
mydirectory/ersapp/__init__.py
...
def create_app(config_name):
webapp = Flask(__name__)
...
return webapp
with a "manager" (see flask-script Manager)
mydirectory/manage.py
from webapp import create_app
...
webapp = create_app(os.getenv('FLASK_CONFIG') or 'default')
manager = Manager(webapp)
...
if __name__ == '__main__':
manager.run()
In this configuration, I trigger my development server with $ python manage.py runserver
whereas before I triggered it with $ python run_web.py
Now, I am struggling with what to put in the uwsgi configuration file to allow this app to be deployed via UWSGI. Specifically, the app
, module
, and callable
variables.
The error I am getting in my logs is:
...
--- no python application found, check your startup logs for errors ---
...
I am also using the flask-script
manager , so what i did was
created a
wsgi.py
.which was like.from app import * application = create_app("development")
then
uwsgi --wsgi-file wsgi.py --callable application
Note: the callable is the flask object name in the wsgi.py
.
这篇关于使用uwsgi和flask-script Manager部署flask应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!