The issue is that your environment variable does NOT exist locally. There are a lot of ways to set environment variables locally.
I highly recommend using the autoenv written by Kenneth Reitz. This is a cool tool you can install locally on your computer. See setting an environment variable in virtualenv for more information.
The way it works is that you define a file called .env
in your project directory, and list all of your environment variables inside of it. For instance:
export DJANGO_SERVER_TYPE=local
Everytime you enter that directory on the command line (like cd ~/my_project
), autoenv will automatically set whatever environment variables you've got in that folder as active. It's very useful.
Anyhow, wherever you're currently storing your environment variables, you'll need to export
them if you don't want to use something like autoenv.
So, let's say you've got a file (env.sh
) that has your environment variables defined in it like so:
DJANGO_SERVER_TYPE=local
You can 'run' this file by saying sh env.sh
. Now, you might expect that this would run, and you would now have DJANGO_SERVER_TYPE
defined in your environment variables, right?
Well, not exactly.
In sh
(the scripting language you're actually using here), you need to put the export
keyword in front of a variable if you want the variable to be exported OUTSIDE of the running script.
So, in order to actually set your variable, you would have to say:
export DJANGO_SERVER_TYPE=local
Then run that file as a script: sh env.sh
. If you do that, you'll notice that now your environment variable IS actually set.
Another useful thing to know while testing this out, is that if you run the env
command on the command line, it will output a list of all environment variables currently set LOCALLY. This is useful for debugging, eg:
env | grep DJANGO_