user3288051
user3288051

Reputation: 614

Environment variables works on Django's server but not on Apache server

When I use the environment variable in Django's server, it works.

SMTP_PASSWORD = os.environ["SMTP_PASSWORD"]

However, when I run the same code on Apache, it doesn't. The code os.environ["..."] just doesn't work.

I am using Windows 10, Python 3.9.5 and Django 3.2.4.

Any idea what is happening?

Upvotes: 0

Views: 201

Answers (1)

Mark2
Mark2

Reputation: 130

You can put environment variables in the apache config.

<VirtualHost hostname:443>
   ...
   SetEnv SMTP_PASSWORD smtp_password
   ...
</VirtualHost>

If you don't want to put sensitive information in apache config you can still include your environment variable in your files, to read it when the server is starting or you can store those variables in your database.

Upvotes: 1

Related Questions