KeyError : APP_SETTINGS
<p>I'm getting a <code>KeyError</code>, this is the <code>apache2/error.log</code>:</p>

<pre><code>tail /var/log/apache2/error.log
[Tue Oct 04 18:07:13.305780 2016] [wsgi:error] [pid 15459:tid 140052675933952] [client 174.58.31.189:56852] mod_wsgi (pid=15459): Target WSGI script '/var/www/FlaskApp/flaskapp.wsgi' cannot be loaded as Python module., referer: http://localhost/login/
[Tue Oct 04 18:07:13.305918 2016] [wsgi:error] [pid 15459:tid 140052675933952] [client 174.58.31.189:56852] mod_wsgi (pid=15459): Exception occurred processing WSGI script '/var/www/FlaskApp/flaskapp.wsgi'., referer: http://localhost/login/
[Tue Oct 04 18:07:13.306787 2016] [wsgi:error] [pid 15459:tid 140052675933952] [client 174.58.31.189:56852] Traceback (most recent call last):, referer: http://45.55.236.208/login/
[Tue Oct 04 18:07:13.306833 2016] [wsgi:error] [pid 15459:tid 140052675933952] [client 174.58.31.189:56852]   File "/var/www/FlaskApp/flaskapp.wsgi", line 7, in &lt;module&gt;, referer: http://localhost/login/
[Tue Oct 04 18:07:13.306842 2016] [wsgi:error] [pid 15459:tid 140052675933952] [client 174.58.31.189:56852]     from FlaskApp import app as application, referer: http://localhost/login/
[Tue Oct 04 18:07:13.306855 2016] [wsgi:error] [pid 15459:tid 140052675933952] [client 174.58.31.189:56852]   File "/var/www/FlaskApp/FlaskApp/__init__.py", line 14, in &lt;module&gt;, referer: http://localhost/login/
[Tue Oct 04 18:07:13.306861 2016] [wsgi:error] [pid 15459:tid 140052675933952] [client 174.58.31.189:56852]     app.config.from_object(os.environ['APP_SETTINGS']), referer: http://localhost/login/
[Tue Oct 04 18:07:13.306872 2016] [wsgi:error] [pid 15459:tid 140052675933952] [client 174.58.31.189:56852]   File "/usr/lib/python3.5/os.py", line 725, in __getitem__, referer: http://localhost/login/
[Tue Oct 04 18:07:13.306892 2016] [wsgi:error] [pid 15459:tid 140052675933952] [client 174.58.31.189:56852]     raise KeyError(key) from None, referer: http://localhost/login/
[Tue Oct 04 18:07:13.306925 2016] [wsgi:error] [pid 15459:tid 140052675933952] [client 174.58.31.189:56852] KeyError: 'APP_SETTINGS', referer: http://localhost/login/
</code></pre>

<p>In my main application I have:</p>

<pre><code>import os
app.config.from_object(os.environ['APP_SETTINGS'])
</code></pre>

<p>and, this is my <code>config.py</code>:</p>

<pre><code># default config
import os

class BaseConfig(object):
    DEBUG = False
    SECRET_KEY = 'jjjjjjj'
    SQLALCHEMY_DATABASE_URI = os.environ['DATABASE_URL']


class DevelopmentConfig(BaseConfig):
    DEBUG = True


class ProductionConfig(BaseConfig):
    DEBUG = False
</code></pre>

<p>What I did: </p>

<pre><code>export APP_SETTINGS="config.DevelopmentConfig"
export DATABASE_URL="postgresql://user:mypassword@localhost/database"
</code></pre>

<p>It doesn't tell me what key is missing or what is wrong, I'm running this app from digitalocean ubuntu, if that helps.</p>

<p>There isn't a way to readily set environment variables in the startup environment for Apache. You would normally set them from the WSGI script file explicitly, or indirectly by having them in some separate file and have the WSGI script file read that and set them for you based on what was set in that separate file. The use of a separate file is where you don't want information in your code repo. That separate file could be under <code>/etc/</code> or elsewhere and only exists on the system you are deploying to.</p>

python python-3.x flask apache2 flask-sqlalchemy