Skip to main content
This guide shows how to deploy a Django application on DCDeploy, covering setup, Docker configuration, environment variables, and best practices.

Quick Start: Hello World

To test the flow, you can deploy a minimal Django app:
  1. Create a Django project locally:
  2. Edit hellosite/settings.py to allow all hosts and read port from environment:
  1. Optionally add a simple view (if needed) in hellosite/urls.py:
  1. Commit and push to your Git provider.

Overview

Django is a high-level Python web framework that promotes rapid development and clean design. On DCDeploy you can deploy Django apps via:
  • Dockerfile (recommended for full control)
  • Build-from-code method (auto-detects Django app) Key concerns include static files, database connections, allowed hosts, and environment configuration.

Prerequisites

  • A Django project with requirements.txt including all dependencies (e.g. Django, gunicorn, psycopg2).
  • settings.py using environment variables for sensitive configs (DB credentials, secret key).
  • STATIC_ROOT configured and static file collection in build or startup.
  • Dockerfile (if using Docker) or autoBuild setup.
  • Git repository with your code.

Step-by-Step Guide

  1. Prepare Your Django App
  • Set environment variables for DJANGO_SECRET_KEY, DATABASE_URL, etc.
  • In settings, allow connections from 0.0.0.0 and the port your service will listen on.
  • Configure ALLOWED_HOSTS (for production, include your custom domain or default).
  • Set up static files:
  1. Add Dockerfile (recommended) Example Dockerfile:
  1. Push Code to Git
  • Initialize repo, commit, push to GitHub or similar.
  • Include .dockerignore to exclude venv, pycache, etc.
  1. Deploy on DCDeploy
  • In DCDeploy dashboard → Environment → Deploy tab.
  • Add a new service → choose Build from Code or Docker Registry.
  • Provide your Git repo or Docker image.
  • Set port to 8000 and protocol (HTTP/HTTPS).
  • Select machine type based on expected traffic.
  • Provide environment variables:
    • DJANGO_SETTINGS_MODULE
    • DJANGO_SECRET_KEY
    • DATABASE_URL
    • Other secrets.
  • Configure static files: ensure collectstatic is run and static served.
  • Adjust scale (minScale/maxScale).
  • Deploy and monitor build & deployment, check revision events. Example Service Configuration

Best Practices

  • Use gunicorn (or similar WSGI) for production, not runserver.
  • Serve static files via built-in mechanisms or via external storage/CDN.
  • Keep SECRET_KEY and other secrets in environment or Secrets management.
  • Use internal networking for DB connections and other internal services.
  • Enable health checks (e.g. /healthz) to verify readiness.
  • If your app is idle, consider scale-to-zero if acceptable.

Troubleshooting