Reputation: 65510
I'm trying to run Django (1.10) but getting an error:
(.venv)$ ./manage.py runserver 0.0.0.0:8000
Traceback (most recent call last):
File "./manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
...
File "/home/myapp/myapp/myapp/myapp/settings/local.py", line 5, in <module>
from .base import *
File "/home/myapp/myapp/myapp/myapp/settings/base.py", line 64, in <module>
'NAME': utils.get_env_setting('RETR_DB_NAME'),
File "/home/myapp/myapp/myapp/common/utils.py", line 13, in get_env_setting
raise ImproperlyConfigured(error_msg)
django.core.exceptions.ImproperlyConfigured: Set the RETR_DB_NAME env variable
But the environment variable is set:
(.venv) $ echo $RETR_DB_NAME
myname
The code in question looks like this:
def get_env_setting(setting):
""" Get the environment setting or return exception """
try:
return environ[setting]
except KeyError:
error_msg = "Set the %s env variable" % setting
raise ImproperlyConfigured(error_msg)
...
'NAME': utils.get_env_setting('RETR_DB_NAME'),
How come I can see the environment variable, but Django can't?
Upvotes: 1
Views: 2196
Reputation: 990
If you're using shells like zsh, make sure to put export key=value
in the config, e.g. ~/.zshrc.
Upvotes: 0
Reputation: 155323
Odds are you forgot to export
it. You can check if that's the problem with:
export -p | fgrep RETR_DB_NAME
which will output nothing if you forgot to export
, and export
can be used to make it exported (whether or not it was already exported, it's not an error to export
twice) with:
export RETR_DB_NAME
Upvotes: 5