I'm pretty new to Django / Python, and I'm trying to figure out how a .env
file relates to a Django project.
Example .env
:
DATABASE_URL=postgres://postgres_user@db:xxxx/postgres_db
DJANGO_SETTINGS_MODULE=spare.settings.dev
SECRET_KEY=example
I did manage to find this Stack Overflow post, which gives some information, but was hoping for a bit more.
.env
file?.env
file, or is it generally a Django-related thing?.env
file typically being called from? In other words, how does the rest of the project know that the .env file exists?django-environ is the Python package that allows you to use Twelve-factor methodology to configure your Django application with environment variables.
env file is a text file containing key value pairs of all the environment variables required by your application. This file is included with your project locally but not saved to source control so that you aren't putting potentially sensitive information at risk.
The . env file contains the individual user environment variables that override the variables set in the /etc/environment file. You can customize your environment variables as desired by modifying your . env file.
We can only guess because we don't have access to your actual environment.
The .env
file may be a container manager thing or something from libraries like python-decouple - for practical effects the .env
will be used to populate the environment variables when the container "boots" or will be used to fill instance settings.
There is a common pattern made popular by the Twelve-Factor app: the item III is "Store config in the environment". Then in the settings.py
file you use the KEY = os.environ.get('KEY', 'defaul_value')
. The idea is to separate instance settings from project settings from code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With