From c331fa992911f8ce8adf47185ea97e551747d1db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Marais?= <4118816+Timer91@users.noreply.github.com> Date: Fri, 26 Nov 2021 11:41:49 +0100 Subject: [PATCH] [FIX] update documentation (#13701) * [FIX] update documentation - add `PYTHONDONTWRITEBYTECODE` environment variable - rename pip package `psycopg2-binary` to `psycopg2` - add db environment variables in docker-compose for a better usage - use `os.environment` in `setting.py` to get environment variables * [fix] update documentation --- samples/django.md | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) 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, }