2

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.

HoldOffHunger
  • 18,769
  • 10
  • 104
  • 133
Pragyan
  • 567
  • 1
  • 5
  • 18
  • The first reference specifically says you tell it if its development or production. You set the environment variable `APP_SETTINGS` to be `"DevelopmentConfig"` or `"ProductionConfig"`. – Peter Jul 27 '20 at 12:16

1 Answers1

3

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.

Emil Vikström
  • 90,431
  • 16
  • 141
  • 175