我使用.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文件:
^{pr2}$如何使用工厂功能部署Flask应用程序以创建应用程序?在
带工厂功能结构的烧瓶应用:
| - Devrupt
| - Devrupt
|- app/
|- templates/
|- static/
|- main/
|- __init__.py
|- errors.py
|- forms.py
|- views.py
|- __init__.py # Factory Function
|- models.py
|- migrations/ # Contains the database migrations scripts
|- tests/ # Where unit tests are written
|- __init__.py
|- test*.py
|- venv/ # Contains the python virtual environment
|- requirements.txt # List package dependencies so that it is easy to regenerate an identical virtual environment on a diff machine
|- config.py # Stores the configuration settings
|- manage.py # Launch the application and other applcation tasks
| - devrupt.wsgi
mod_wsgi (Apache)声明“如果没有用于创建应用程序的工厂函数,而是一个单实例实例,则可以直接将其作为应用程序导入。”
app/init.py(工厂函数):
# Application Package Constructor
from flask import Flask, render_template
from flask.ext.bootstrap import Bootstrap
from flask.ext.mail import Mail
from flask.ext.moment import Moment
from config import config
bootstrap = Bootstrap()
moment = Moment()
def create_app(config_name):
app = Flask(__name__)
app.config.from_object(config[config_name])
config[config_name].init_app(app)
bootstrap.init_app(app)
moment.init_app(app)
# Attach Routes and custom error messages here
from .main import main as main_blueprint
app.register_blueprint(main_blueprint)
return app
要使它在工厂函数应用程序中工作,我需要做些什么修改?在
您只需要确保您的
.wsgi
文件中有一个应用程序对象。可以使用工厂函数创建此对象。例如:就这么简单! 但要真正地阐明,修改德夫鲁普.wsgi收件人:
^{pr2}$相关问题 更多 >
编程相关推荐