diff --git a/samples/django.md b/samples/django.md index bc260b9a86..affb33805c 100644 --- a/samples/django.md +++ b/samples/django.md @@ -30,6 +30,7 @@ and a `docker-compose.yml` file. (You can use either a `.yml` or `.yaml` extensi ```dockerfile # syntax=docker/dockerfile:1 FROM python:3 + ENV PYTHONDONTWRITEBYTECODE=1 ENV PYTHONUNBUFFERED=1 WORKDIR /code COPY requirements.txt /code/ @@ -50,7 +51,7 @@ and a `docker-compose.yml` file. (You can use either a `.yml` or `.yaml` extensi 6. Add the required software in the file. Django>=3.0,<4.0 - psycopg2-binary>=2.8 + psycopg2>=2.8 7. Save and close the `requirements.txt` file. @@ -74,10 +75,6 @@ and a `docker-compose.yml` file. (You can use either a `.yml` or `.yaml` extensi image: postgres volumes: - ./data/db:/var/lib/postgresql/data - environment: - - POSTGRES_DB=postgres - - POSTGRES_USER=postgres - - POSTGRES_PASSWORD=postgres web: build: . command: python manage.py runserver 0.0.0.0:8000 @@ -85,6 +82,10 @@ and a `docker-compose.yml` file. (You can use either a `.yml` or `.yaml` extensi - .:/code ports: - "8000:8000" + environment: + - POSTGRES_NAME=postgres + - POSTGRES_USER=postgres + - POSTGRES_PASSWORD=postgres depends_on: - db ``` @@ -169,12 +170,16 @@ In this section, you set up the database connection for Django. ```python # settings.py + import os + + [...] + DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql', - 'NAME': 'postgres', - 'USER': 'postgres', - 'PASSWORD': 'postgres', + 'NAME': os.environ.get('POSTGRES_NAME'), + 'USER': os.environ.get('POSTGRES_USER'), + 'PASSWORD': os.environ.get('POSTGRES_PASSWORD'), 'HOST': 'db', 'PORT': 5432, }