[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
This commit is contained in:
Jérémie Marais 2021-11-26 11:41:49 +01:00 committed by GitHub
parent f5513bd89b
commit c331fa9929
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 8 deletions

View File

@ -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,
}