Help Center

Python + Django + PostgreSQL + Redis

Django is a high-level web framework written in Python that follows the MVT pattern and provides out of the box the pieces every application needs: ORM, admin panel, authentication, migrations and protection against the most common web attacks.

This Stack combines it with PostgreSQL as a relational database and Redis as an in-memory store, the typical configuration when the application needs caching, shared sessions or a task queue with Celery.

Services included

Besides your application, the Stack brings up PostgreSQL, Redis, an nginx that receives traffic on port 80, an automatic backups service and the web file manager.

Project structure

text
.
β”œβ”€β”€ app
β”‚   β”œβ”€β”€ helloworld
β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   β”œβ”€β”€ settings.py
β”‚   β”‚   β”œβ”€β”€ urls.py
β”‚   β”‚   β”œβ”€β”€ views.py
β”‚   β”‚   └── wsgi.py
β”‚   β”œβ”€β”€ manage.py
β”‚   └── requirements.txt
β”œβ”€β”€ backup
β”‚   └── backup-runner.sh
β”œβ”€β”€ nginx
β”‚   └── default.conf
β”œβ”€β”€ .env.example
β”œβ”€β”€ app.Dockerfile
└── compose.yaml

Getting started

Install the Stack and bring it up:

bash
docker-deploy-stack --stack python/django-postgres-redis
cd /root/stack/python/django-postgres-redis
docker compose up -d

Then replace the example application with yours, from Git, via SFTP or from the web file manager, following how-do-i-deploy-an-application-on-a-stack.md. Your code goes in the app/ folder.

Whenever you update the code, apply the changes:

bash
docker compose up -d --build

Configuration

Editable values are in the Stack’s .env file:

Variable Default Purpose
APP_PORT 80 Public port of the Stack.
APP_ENV development Application environment.
DB_NAME django Database name.
DB_USER django Database user.
BACKUP_ENABLED 1 Automatic backups: 1 enabled, 0 disabled.
BACKUP_INTERVAL_SECONDS 86400 How many seconds between backups.
BACKUP_RETENTION_DAYS 7 How many days backups are retained.
POSTGRES_VERSION 16-alpine Image version.
REDIS_VERSION 7-alpine Image version.

After changing it, apply the changes with docker compose up -d.

Useful commands

bash
docker compose ps          # view the containers that are running
docker compose logs -f     # view live logs
docker compose restart     # restart the services
docker compose down        # stop and remove the containers
Guide g.0317 Β· Source version 1 Β· en