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.

2
  • "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, 2017 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. May 10, 2017 at 16:04

1 Answer 1

0

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .