1#settings.py
2
3EMAIL_PASS = "FOO"
4
5# in any file
6from django.conf import settings
7email_password = settings.EMAIL_PASS #to access that variable.
1$ pip install django-environ
2
3#In settings.py
4import environ
5# Initialise environment variables
6env = environ.Env()
7environ.Env.read_env()
8
9#In the same directory as settings.py, create a file called ‘.env’
10#Declare your environment variables in .env
11#Make sure you don’t use quotations around strings
12#Example:
13DATABASE_NAME=postgresdatabase
14#IMPORTANT: Add your .env file to .gitignore
15#Use the variables as follows:
16DATABASES = {
17...
18‘NAME’: env(‘DATABASE_NAME’),
19...
20}