In a flask application I wrote, I make use of an external library which can be configured using environment variables. Note: I wrote this external library myself. So I c
@rapadura answer is correct in that you don't have direct access to the SetEnv
values in your Apache config, but you can work around it.
If you add a wrapper around application
in your app.wsgi
file you can set the os.environ
on each request. See the following modified app.wsgi
for an example:
activate_this = '/var/www/michel/testenv/env/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))
from os import environ, getcwd
import logging, sys
from testenv.webui import app as _application
# You may want to change this if you are using another logging setup
logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)
LOG = logging.getLogger(__name__)
LOG.debug('Current path: {0}'.format(getcwd()))
# Application config
_application.debug = False
def application(req_environ, start_response):
environ['MYAPP_CONF'] = req_environ['MYAPP_CONF']
return _application(req_environ, start_response)
If you have set more environment variables in your Apache config, then you need to explicitly set each of them in the application
wrapper function.