django container can’t access postgres container

I am trying to have my database and my django rest api connect using docker-compose. However, my django container is giving me this error:

django.db.utils.OperationalError: could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
could not connect to server: Cannot assign requested address
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?

Postgres starts up normally, and I am able to access it locally using the terminal. I’m just not sure why my django container can’t connect.

$ psql -h 0.0.0.0 -p 5432 -U bli1 -d redribbon
Password for user bli1:
psql (12.1)
Type "help" for help.

Within my settings.py for django this is my database values

DATABASES = {
    "default": {
        "ENGINE": "django.db.backends.postgresql_psycopg2",
        "NAME": "redribbon",
        "USER": "bli1",
        "PASSWORD": "password",
        "HOST": "0.0.0.0",
        "PORT": "5432",
    }
}

docker-compose.yml

version: "3"
services:
  postgres:
    image: postgres:latest
    restart: always
    ports:
      - "5432:5432"
    volumes:
      - ./pgdata:/var/lib/postgresql/data/
    environment:
      POSTGRES_DB: redribbon
      POSTGRES_USER: bli1
      POSTGRES_PASSWORD: password
  api:
    build:
      dockerfile: Dockerfile.dev
      context: ./redribbon-api
    command: python manage.py runserver 0.0.0.0:8000
    volumes:
      - ./redribbon-api/api:/usr/src/api
    depends_on:
      - postgres
    ports:
      - "8000:8000"

updates:

Within the django container, I am able to ping postgres and got this as a response

# ping postgres
PING postgres (172.19.0.2) 56(84) bytes of data.
64 bytes from redribbon_postgres_1.redribbon_default (172.19.0.2): icmp_seq=1 ttl=64 time=0.175 ms
64 bytes from redribbon_postgres_1.redribbon_default (172.19.0.2): icmp_seq=2 ttl=64 time=0.096 ms
64 bytes from redribbon_postgres_1.redribbon_default (172.19.0.2): icmp_seq=3 ttl=64 time=0.097 ms

I even tried changing "HOST": "0.0.0.0", to "HOST": "postgres", in my settings.py but I am getting the same error as above

Source: StackOverflow