foreman reads from .env. manage.py doesn't. Let's fix that.
Project description
foreman reads from .env. manage.py doesn’t. Let’s fix that.
Original implementation was written by @jacobian.
Tested on Python 2.7, 3.3, 3.4, and 3.5.
Installation
pip install django-dotenv
Usage
Your manage.py should look like:
#!/usr/bin/env python
import os
import sys
import dotenv
if __name__ == "__main__":
dotenv.read_dotenv()
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
You can also pass read_dotenv() an explicit path to the .env file, or to the directory where it lives. It’s smart, it’ll figure it out.
Check out tests.py to see all the supported formats that your .env can have.
Using with WSGI
If you’re running Django with WSGI and want to load a .env file, your wsgi.py would look like this:
import os
import dotenv
from django.core.wsgi import get_wsgi_application
dotenv.read_dotenv(os.path.join(os.path.dirname(os.path.dirname(__file__)), '.env'))
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings")
application = get_wsgi_application()
That’s it. Now go 12 factor the crap out of something.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
django-dotenv-1.4.1.tar.gz
(4.1 kB
view hashes)
Built Distribution
Close
Hashes for django_dotenv-1.4.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2930f6b0c0955ac150e1ca9ac01e84afa71efdbb544dea7155f026e20e401305 |
|
MD5 | 5cdc128417494f756cc706fa3ffe1c42 |
|
BLAKE2b-256 | 897dc9b430712693510868c734db5e566f38e6018400c85b87a4d00d2adb0770 |