Skip to content

Commit 0ddc633

Browse files
committed
Add manage.py to project template.
This allows an IDD project to be run directly via `./manage.py`, without using `go.sh` to configure the environment, and therefore works in VS Code launch configs. The `manage.py` file defines the one required `ixc-django-docker` env var (`PROJECT_DIR`), and we use `environs` to load the `.env` file into `os.environ` in settings.
1 parent cad3b5b commit 0ddc633

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

ixc_django_docker/settings/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import environs
12
import os
23

34
from django.core.exceptions import ImproperlyConfigured
@@ -13,7 +14,11 @@ def _(module, from_dir):
1314

1415

1516
# Get project directory from environment. This MUST already be defined.
16-
PROJECT_DIR = os.environ['PROJECT_DIR']
17+
PROJECT_DIR = env('PROJECT_DIR')
18+
19+
# Load `.env` file into `os.environ`.
20+
env = environs.Env()
21+
env.read_env(os.path.join(PROJECT_DIR, '.env'))
1722

1823
# Base settings.
1924
BASE_SETTINGS = os.environ.get(

project_template/manage.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env python
2+
"""Django's command-line utility for administrative tasks."""
3+
import os
4+
import sys
5+
6+
# Define required `ixc-django-docker` env var.
7+
os.environ['PROJECT_DIR'] = os.path.abspath(os.path.dirname(__file__))
8+
9+
10+
def main():
11+
"""Run administrative tasks."""
12+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', '{{ project_name }}.settings')
13+
try:
14+
from django.core.management import execute_from_command_line
15+
except ImportError as exc:
16+
raise ImportError(
17+
"Couldn't import Django. Are you sure it's installed and "
18+
"available on your PYTHONPATH environment variable? Did you "
19+
"forget to activate a virtual environment?"
20+
) from exc
21+
execute_from_command_line(sys.argv)
22+
23+
24+
if __name__ == '__main__':
25+
main()

0 commit comments

Comments
 (0)