I set up the django setting.py like this:
import os
from django.core.exceptions import ImproperlyConfigured
def get_env_variable(var_name):
try:
return os.environ[var_name]
except KeyError:
error_msg = "Set the %s environment variable" % var_name
raise ImproperlyConfigured(error_msg)
The environment variables were configed correctly. When working with the django built in web server, everything was ok. But working with apache and wsgi, it raised an KeyError.
According to Cannot get environment variables in Django settings file, the problem is solved. But why cannot apache get the system environment variables?
UPDATED: The environment variables were set in .bashrc.