使用uwsgi和flask-script Manager部署flask应用程序 [英] deploying flask app with uwsgi and flask-script Manager

查看:1354
本文介绍了使用uwsgi和flask-script Manager部署flask应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

传统上,我已经配置了UWSGI配置文件来调用如下的应用程序:

  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

带有管理员(参见

  mydirectory / manage.py 
$ rel =nofollow> flask-script Manager
) webapp import create_app
...
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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆