我已使用.wsgi文件中的以下配置设法使用wsgi和apache2部署单瓶版本应用程序。
#!/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>
如何使用工厂功能部署Flask应用程序以创建应用程序?
具有工厂功能结构的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)表示&#34;如果您没有用于创建应用程序的工厂函数,而是单例实例,则可以直接将其作为应用程序导入。&#34;
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
我必须做些哪些修改才能使其在工厂功能应用程序上工作?