Use venv from mod-apache

This commit is contained in:
Xavier Bustamante Talavera 2018-09-18 16:05:54 +02:00
parent 47b3f0e3c1
commit 10e56e8ed6
2 changed files with 7 additions and 20 deletions

View File

@ -8,11 +8,13 @@ Define appdir /path/to/app/dir
# The path where the app directory is. Apache must have access to this folder.
Define wsgipath ${appdir}/wsgi.wsgi
# The location of the .wsgi file
Define pyvenv /path/to/venv
# The path where the virtual environment is (the folder containing bin/activate)
<VirtualHost *:80>
ServerName ${servername}
WSGIDaemonProcess "${servername}" threads=5 lang='en_US.UTF-8' locale='en_US.UTF-8'
WSGIDaemonProcess "${servername}" threads=5 lang='en_US.UTF-8' locale='en_US.UTF-8' python-home="${pyvenv}"
WSGIScriptAlias / ${wsgipath}
# pass the required headers through to the application

View File

@ -3,7 +3,7 @@ An exemplifying Apache python WSGI to a Devicehub app.
Based in http://flask.pocoo.org/docs/0.12/deploying/mod_wsgi/
You only need to modify ``app_dir`` and ``venv``.
You only need to modify ``app_dir``.
"""
from pathlib import Path
@ -11,28 +11,13 @@ from pathlib import Path
import sys
app_dir = Path(__file__).parent
"""
The **directory** where app.py is located.
Change this accordingly.
"""
"""The **directory** where app.py is located. Change this accordingly."""
assert app_dir.is_dir(), 'app_dir must point to a directory: {}'.format(app_dir)
app_dir = str(app_dir.resolve())
venv = Path(__file__).parent.parent / 'venv' / 'bin' / 'activate_this.py'
"""
The location of the ``activate_this.py`` file of the virtualenv.
Change this accordingly.
"""
assert venv.is_file(), 'venv must point to a file: {}'.format(venv)
venv = str(venv.resolve())
# Load the virtualenv
# -------------------
_globals = dict(__file__=venv)
exec(open(venv).read(), _globals)
# Load the app
# ------------
sys.path.insert(0, str(app_dir))
# noinspection PyUnresolvedReferences
from app import app as application
from app import app as application