Thanks for reading my article first. Python 3 Django Environment Variable Module Tutorial to Setup and Load Variables From env File Format We are going to learn more about this in this article. Let’s go into the article
When hosting a Python WSGI compatible framework such as Django on Apache with mod_wsgi, only context variables in the os.environ dictionary are in the context of the script starting in Apache. But instead of messing with Apache’s service manager settings (eg systemd or systemctl), there is a better way.
Python 3 Django Environment Variable Module Tutorial to Setup and Load Variables From env File Format
This module helps to set environment variable for your Django application from a .env.py or .env.yml file placed inside the project directory.
pip install django-envie
To use, create an environment file, save as either a .env.py or .env.yml file format in your django project (inside the project directory) or repository root (outside the project directory).
The .env.py file for a django project should be formatted this way:
DB_NAME = "sector_seven" DB_USER = "homer_simpson" DB_PASSWORD = "Close, but you're way off."
If using .env.yml file format
DB_NAME: "sector_seven" DB_USER: "homer_simpson" DB_PASSWORD: "Close, but you're way off."
In the project settings script, include this snippet:
from django_envie import load_vars load_vars()
Accessing environment variables anywhere can be done by using
KEY = VALUE
KEY = "VALUE"
Check out the documentation for this project here
Python 3 Django Environment Variable Module Tutorial to Setup and Load Variables From env File Format We hope this article solves all your doubts. If in doubt let me know.