Skip to content

zeropsio/recipe-django

Repository files navigation

Zerops x Django

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.

django


Deploy on Zerops

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.

Deploy on Zerops


Recipe features

  • 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)

Production vs. development

Base of the recipe is ready for production, the difference comes down to:

  • Use highly available version of the PostgreSQL database (change mode from NON_HA to HA 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 YAML app 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 add APP_DOMAIN secret variable (in recipe YAML, app service section)
  • Disable public access to Adminer or remove it altogether (remove service adminer from recipe YAML)


Changes made over the default installation

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 your project/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.

About

Zerops w/ Django

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 5