diff --git a/ixc_django_docker/settings/__init__.py b/ixc_django_docker/settings/__init__.py index efb804f..461a69d 100644 --- a/ixc_django_docker/settings/__init__.py +++ b/ixc_django_docker/settings/__init__.py @@ -1,3 +1,4 @@ +import environs import os from django.core.exceptions import ImproperlyConfigured @@ -13,7 +14,11 @@ def _(module, from_dir): # Get project directory from environment. This MUST already be defined. -PROJECT_DIR = os.environ['PROJECT_DIR'] +PROJECT_DIR = env('PROJECT_DIR') + +# Load `.env` file into `os.environ`. +env = environs.Env() +env.read_env(os.path.join(PROJECT_DIR, '.env')) # Base settings. BASE_SETTINGS = os.environ.get( diff --git a/project_template/manage.py b/project_template/manage.py new file mode 100755 index 0000000..140d272 --- /dev/null +++ b/project_template/manage.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python +"""Django's command-line utility for administrative tasks.""" +import os +import sys + +# Define required `ixc-django-docker` env var. +os.environ['PROJECT_DIR'] = os.path.abspath(os.path.dirname(__file__)) + + +def main(): + """Run administrative tasks.""" + os.environ.setdefault('DJANGO_SETTINGS_MODULE', '{{ project_name }}.settings') + try: + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) from exc + execute_from_command_line(sys.argv) + + +if __name__ == '__main__': + main()