0

i am doing a python-django project, And what i want to do is, i want to set

variables like password,db_name etc as an environment variable. And i want

to access it as os.environ["db_name"]

i tried like this

inside /home/thameem/Django_projects/lotus/env_var

export db_name="thameem"

inside /etc/environment file

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"


PATH="$PATH:/home/thameem/Django_projects/lotus/env_var" 

and in terminal i tried :

echo $db_name 

but it does not shows the value of db_name

if the question is not correct, somebody please correct the question

i checked this one :: How do I add environment variables?

Thameem
  • 101

1 Answers1

3

If you want to keep the assignments in a separate env_var file, you would need to source it from one of your shell's startup files, rather than adding it to your PATH

For example, you could add something like

if [ -r "$HOME/Django_projects/lotus/env_var" ]; then
  . "$HOME/Django_projects/lotus/env_var"
fi

to the bottom of your ~/.profile

I don't recommend adding it to a system-wide file such as /etc/profile since the file is in your home directory.

steeldriver
  • 142,475