By the end of this lesson, you should be able to...
.env
file..env
file to hide secrets such as API keys and retrieve them in your code.Vid 1 - Walking through a virtual environment and accessing a SECRET_KEY
Vid 1 - Walking through a virtual environment and accessing a SECRET_KEY
Go back to your Homework 3 (More Forms) submission and use a .env
file to hide the API key for the GIF Search API. Then in the code, call load_dotenv()
and use the os.getenv()
library function to retrieve and use it.
<aside> 🤔 How can we easily manage configuration values, such as the URL for a database connection or the production server information, spread out in multiple files of a project?
</aside>
Any project that utilizes servers and databases, or multiple global constants, will require environment variables (sometimes synonymous with configuration variables).
<aside> 💡 A variable that contains information required in a global scope that references details about how to connect to external components or internal settings repeated in multiple files can be definied as a environment variable.
</aside>
Examples of environment variables: