env
variables in DjangoEasiest way is to create .env
file manually or add the environment variables in the ec2 instance.
environs
packagepip install environs
.env
file:
export MAX_CONNECTIONS=100 export SHIP_DATE='1984-06-25'
from environs import env env.read_env() # read .env file, if it exists max_connection = env("MAX_CONNECTIONS") # => 100 non_exist_secret = env("SECRET") # => raises error if not set
Importing with default value when the import fails:
MY_API_URL = env.url( "MY_API_URL", default=urlparse("http://api.example.com"), )