Last active
September 6, 2018 08:06
-
-
Save gauravvjn/4a6e5c1e1ded0759779674f308caaa23 to your computer and use it in GitHub Desktop.
Dynamic env variables load from .env file while executing manage.py <command>
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import os | |
import sys | |
if __name__ == "__main__": | |
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "src.settings.base") | |
from django.core.management import execute_from_command_line | |
# ---------- 5 lines ------------ | |
with open('.env') as f: | |
for e in f.readlines(): | |
if e.strip(): | |
k, v = list(map(lambda x: x.strip(), e.split('=', 1))) | |
os.environ.setdefault(k, v) | |
execute_from_command_line(sys.argv) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment