Forums

Using a config.cfg file in my web app?

Im trying to use a config.cfg file in my web app. I have done

app.config.from_envvar('APP_SETTINGS')

Then opened a bash console in the main directory of my site and done

export APP_SETTINGS=config.cfg

but that didnt work so i seperated it and did

export APP_SETTINGS

APP_SETTINGS=config.cfg

But i keep getting this error.

2018-01-13 19:57:55,800: Error running WSGI application

2018-01-13 19:57:55,803: RuntimeError: The environment variable 'APP_SETTINGS' is not set and as such configuration could not be loaded. Set this variable and make it point to a configuration file

What am I doing wrong?

Setting an environment variable in a Bash console only affects the specific console where you set it -- that's why you're not seeing any effect when you do it.

The easiest way to set an environment variable so that it's picked up inside your webapp code is to do it in the WSGI file -- there's a link on the "Web" page. You need to do something like this:

import os

os.environ["APP_SETTINGS"] = "/home/mexO/config.cfg"

...replacing "/home/mexO/config.cfg" with the full path to your config file. The code needs to go at the top of the WSGI file.