Deploy a Django app on Miget in a few minutes. Miget’s Python buildpack auto-detects Django, installs your dependencies, and serves the app with gunicorn - no Dockerfile required.

Prerequisites

  • A Miget account
  • Git installed locally
  • A Django project with a requirements.txt that includes gunicorn
Every app on Miget must listen on 0.0.0.0:5000. Miget sets an immutable PORT=5000 environment variable, and public ingress only reaches port 5000. See Ports for details.

Prepare your project

Miget’s buildpacks detect Python from requirements.txt (or pyproject.toml). When a Django project is found, it is served with gunicorn.
  1. Add gunicorn. Make sure gunicorn is listed in your requirements.txt.
  2. Confirm your WSGI module. Your project needs a WSGI entry point, typically <project>/wsgi.py (created by default with django-admin startproject).
  3. Bind to the right port (optional). The buildpack starts gunicorn for you. If you need to control the start command, add a Procfile to your project root:
    Procfile
    web: gunicorn <project>.wsgi --bind 0.0.0.0:5000
    
    Replace <project> with your Django project package name (the directory containing wsgi.py).

Production settings

Set these Django settings through environment variables rather than hardcoding them. Add them in the app dashboard - see Using secrets.
  • DEBUG=False
  • SECRET_KEY - a strong, unique key
  • ALLOWED_HOSTS - include your Miget app domain (or read it from an environment variable)
Read them in settings.py, for example:
settings.py
import os

DEBUG = os.environ.get("DEBUG", "False") == "True"
SECRET_KEY = os.environ["SECRET_KEY"]
ALLOWED_HOSTS = os.environ.get("ALLOWED_HOSTS", "").split(",")
For static files, either run python manage.py collectstatic as a pre- or post-deploy step, or use WhiteNoise to serve them directly from your app.

Deploy with git push

1

Create the application

Go to app.miget.com, click New and select Application. Give it a name, select the resource (plan) to deploy into, and click Next.
2

Choose the build method

Select Auto detection (Miget Buildpacks), pick an instance size, and click Next.
3

Pick git push

Choose git push as the deployment method, click Create, and copy the deployment token shown.
4

Push your code

Add the Miget remote and push:
git remote add miget https://git.<region>.miget.io/<your-miget-name>/<app-name>
git push miget
Replace <region>, <your-miget-name>, and <app-name> with the values shown in the dashboard. Miget builds and deploys your app on each push. See Git push to builder for the full flow.
This guide uses git push, but it’s one of several ways to deploy. You can also connect a GitHub repository for auto-deploys and pull request previews, deploy from a public Git repository, or push a prebuilt container image. See all deployment methods.

Connect a database

Give your app a managed PostgreSQL database from the dashboard.
1

Add the PostgreSQL addon

Open the Addons tab for your app and add a PostgreSQL addon. Miget provisions the database and auto-injects a DATABASE_URL environment variable (postgres://...). See PostgreSQL.
2

Read DATABASE_URL in settings

Add dj-database-url to your requirements.txt and read the connection string in settings.py:
settings.py
import dj_database_url

DATABASES = {
    "default": dj_database_url.config(),
}
dj_database_url.config() reads DATABASE_URL by default.
3

Run migrations

Run migrations as a post-deploy step:
python manage.py migrate
Never commit your SECRET_KEY, database credentials, or other secrets to git. Store them as environment variables - see Using secrets.

Next steps

Add a custom domain

Point your own domain at your Django app and remember to add it to ALLOWED_HOSTS.

Manage secrets

Set DEBUG, SECRET_KEY, and ALLOWED_HOSTS as environment variables.

PostgreSQL databases

Learn more about provisioning and connecting managed databases.

How the Fair Scheduler works

Understand how Miget shares compute across your apps.