Search code examples
pythonmod-wsgipyramid

How to call a function in another python file in my wsgi file?


I am using mod_wsgi with pyramid and have different wsgi files per environment/server like the pyramid-test.wsgi and pyramid-prod.wsgi

These files contains code to set environment variables that are different per environment. Example:

os.environ['SQLALCHEMY_URL'] = 'TODO'

I try to move this code to a file called settings.py that will be called in the .wsgi file. These settings files will be hold next to the .wsgi file or preferable in a secure sub dir, such that others can't read the settings (like db password), but can however deploy a new version and overwrite the .wsgi file such that the app is automatically reloaded by Apache.

How can I call the python code in the settings.py file from the .wsgi file? When I try to do that, it can't find it, as it's not part of the app module.


Solution

  • Presuming you are using recommended separate mod_wsgi daemon process group for each application instance, set the python-path option of the WSGIDaemonProcess directive for each to include the directory where your instance specific settings module is. A normal import should then work.