Python 如何部署具有工厂功能的Flask应用程序来创建应用程序

Python 如何部署具有工厂功能的Flask应用程序来创建应用程序,python,flask,apache2,mod-wsgi,wsgi,Python,Flask,Apache2,Mod Wsgi,Wsgi,我已经使用.wsgi文件中的以下配置成功地使用wsgi和apache2部署了一个singleton flask应用程序 #!/usr/bin/python import sys import logging logging.basicConfig(stream=sys.stderr) sys.path.insert(0,"/var/www/Devrupt/") from Devrupt import app as application application.secret_key = 'Ad

我已经使用.wsgi文件中的以下配置成功地使用wsgi和apache2部署了一个singleton flask应用程序

#!/usr/bin/python
import sys
import logging
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0,"/var/www/Devrupt/")

from Devrupt import app as application
application.secret_key = 'Add your secret key'

activate_this = '/var/www/Devrupt/venv/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))
我的Apache2.conf文件:

<VirtualHost *:80>
        ServerName devrupt.com
        ServerAdmin lui@devrupt.com
        WSGIScriptAlias / /var/www/Devrupt/devrupt.wsgi
        <Directory /var/www/Devrupt/Devrupt/>
                Order allow,deny
                Allow from all
        </Directory>
        Alias /static /var/www/Devrupt/Devrupt/static
        <Directory /var/www/Devrupt/Devrupt/static/>
                Order allow,deny
                Allow from all
        </Directory>
        ErrorLog ${APACHE_LOG_DIR}/error.log
        LogLevel warn
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
声明“如果您没有用于创建应用程序的工厂函数,但有一个单例实例,则可以直接将该实例作为应用程序导入。”

app/init.py(工厂功能):


我需要做些什么才能使它在Factory Function应用程序上工作?

您只需要确保您的
.wsgi
文件中有一个应用程序对象。可以使用factory函数创建此对象。例如:

from Devrupt import application_factory
application = application_factory()
就这么简单! 但要真正说明这一点,请将devrupt.wsgi修改为:

#!/usr/bin/python
activate_this = 'var/www/Devrupt/venv/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))
import sys
import logging
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0,"/var/www/")

from Devrupt import create_app
application = create_app('development')

您只需要确保在
.wsgi
文件中有一个应用程序对象。可以使用factory函数创建此对象。例如:

from Devrupt import application_factory
application = application_factory()
就这么简单! 但要真正说明这一点,请将devrupt.wsgi修改为:

#!/usr/bin/python
activate_this = 'var/www/Devrupt/venv/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))
import sys
import logging
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0,"/var/www/")

from Devrupt import create_app
application = create_app('development')

你为什么需要一个工厂?如果你成功地以单身人士的身份跑步,你就没事了。我们不能告诉您是否需要更改,因为工厂与目录结构无关,它是您在代码中定义的。你写过工厂函数吗?如果没有,那就是你需要开始的地方。为什么你需要一个工厂?如果你成功地以单身人士的身份跑步,你就没事了。我们不能告诉您是否需要更改,因为工厂与目录结构无关,它是您在代码中定义的。你写过工厂函数吗?如果没有,那就是你需要开始的地方。所以我在问题中添加了我的工厂函数(app/\uuu init\uuuu.py)的代码。如何将应用程序对象添加到.wsgi文件中?因此,我在问题中添加了我的工厂函数(app/_uinit__u;u.py)的代码。如何将应用程序对象添加到.wsgi文件中?