Django is a high-level Python web framework that encourages rapid development and clean, pragmatic design. This recipe aims to showcase few advanced Django concepts and how to integrate them with Zerops, all through a simple file upload demo application.
You can either click the deploy button to deploy directly on Zerops, or manually copy the import yaml to the import dialog in the Zerops app.
- Load balanced Django web app running on Zerops Python service
- Served by production-ready application server Gunicorn
- Zerops PostgreSQL 16 service as database
- Zerops Object Storage (S3 compatible) service as file system
- Automatic Django database migrations, static files collection and superuser seeding
- Utilization of Zerops built-in environment variables system
- Logs accessible through Zerops GUI
- Mailpit as SMTP mock server
- Adminer for quick database management tool
- Unlocked development experience:
- Access to database and mail mock through Zerops project VPN (
zcli vpn up
) - Prepared
.env.dist
file (cp .env.dist .env
and change ***** secrets found in Zerops GUI)
- Access to database and mail mock through Zerops project VPN (
Base of the recipe is ready for production, the difference comes down to:
- Use highly available version of the PostgreSQL database (change
mode
fromNON_HA
toHA
in recipe YAML,db
service section) - Use at least two containers for Django service to achieve high reliability and resilience (add
minContainers: 2
in recipe YAML,app
service section) - Use production-ready third-party SMTP server instead of Mailpit (change
MAIL_
secret variables in recipe YAMLapp
service) - Since the Django app will run behind our HTTP balancer proxy, add your domain/subdomains to
recipe/settings.py
CSRF_TRUSTED_ORIGINS
setting or addAPP_DOMAIN
secret variable (in recipe YAML,app
service section) - Disable public access to Adminer or remove it altogether (remove service
adminer
from recipe YAML)
If you want to modify your existing Django app to efficiently run on Zerops, these are the general steps we took:
- Add zerops.yml to your repository, our example includes idempotent migrations, static files collection and optimized build process
- Run
pip install django-storages
and change storage settings section in yourproject/settings.py
to support S3 compatible Object Storage file system (more info here) - Utilize Zerops environment variables and secrets to set up S3 for file system, database access, mailer and trusted hosts to work with reverse proxy load balancer
- Add init commands for your deployments to migrate database and collect static images
Need help setting your project up? Join Zerops Discord community.