Different values for env vars based on the environment

Viewed 256

Currently, I have a .env file with development and production configuration, every time I have to comment out the development configuration in production and production configuration in development.How can I make it dynamic? I found the below resources,

Reference 1
Reference 2

But I am unable to understand how I will access it.Currently I am importing the env variables in settings.py and assigning it to the variable as below

DB_NAME = os.getenv("db_name")
DB_PASS = os.getenv("db_password")

I am using fastapi as framework.

1 Answers

The .env file should not be committed to source control. Normally you commit a file .env.example where you list which variables are available. Then in each environment you create a .env file unique to that environment.

If you are deploying with rsync or similar tool, make sure you exclude the .env file so you don't overwrite it.

Related