0

In .profile found at /home/myuser/, I set an environment variable as follows: export API_TOKEN=xxxxyyyyxxxxyyyyyxxxxxyyyyyxx, and then running source ~/.profile.

This server has a Django app on it; where I import the env variable in settings.py (via API_TOKEN = os.environ.get('API_TOKEN','1')) and then use it to call an analytics API I'm using for my app.

The problem is that Django is unable to import the token at all.

When I do env in the terminal, I do see API_TOKEN=xxxxyyyyxxxxyyyyyxxxxxyyyyyxx among the list of environment variables printed. What could be going wrong, and how can I diagnose the problem?


Note that I do not see the token printed if I do env in super user. Could that be an issue? But there are several other env variables I'm using in this way, and those import correctly even though they don't appear for super user.

Hassan Baig
  • 2,325
  • 12
  • 29
  • 48
  • "run a Django app" ... how? Webservices typically do not poke around in user dot files, especially if they are started by the init system. – thrig May 10 '17 at 15:48
  • @thrig: I got the point, you mean I should interface it via the web application server. If you add that as an answer, I'll accept it. – Hassan Baig May 10 '17 at 16:04

1 Answers1

0

I passed the environment variable values separately through my application webserver conf, only then was my app able to import the value correctly.

Hassan Baig
  • 2,325
  • 12
  • 29
  • 48