--- title: "Deploy a Django App" description: "Deploy a Django project on Miget with git push, gunicorn, and a managed PostgreSQL database." --- 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](https://app.miget.com) - 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](/networking/ports) for details. ## Prepare your project Miget's [buildpacks](/overview/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 `/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: ```text Procfile web: gunicorn .wsgi --bind 0.0.0.0:5000 ``` Replace `` 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](/deployments/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: ```python 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](https://whitenoise.readthedocs.io/) to serve them directly from your app. ## Deploy with git push Go to [app.miget.com](https://app.miget.com), click **New** and select **Application**. Give it a name, select the resource (plan) to deploy into, and click **Next**. Select **Auto detection (Miget Buildpacks)**, pick an instance size, and click **Next**. Choose **git push** as the deployment method, click **Create**, and copy the deployment token shown. Add the Miget remote and push: ```bash git remote add miget https://git..miget.io// git push miget ``` Replace ``, ``, and `` with the values shown in the dashboard. Miget builds and deploys your app on each push. See [Git push to builder](/deployments/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](/deployments/github-integration) for auto-deploys and pull request previews, deploy from a public Git repository, or push a prebuilt [container image](/deployments/container-registry). See [all deployment methods](/deployments/how-it-works). ## Connect a database Give your app a managed PostgreSQL database from the dashboard. 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](/databases/postgresql). Add `dj-database-url` to your `requirements.txt` and read the connection string in `settings.py`: ```python settings.py import dj_database_url DATABASES = { "default": dj_database_url.config(), } ``` `dj_database_url.config()` reads `DATABASE_URL` by default. Run migrations as a post-deploy step: ```bash python manage.py migrate ``` Never commit your `SECRET_KEY`, database credentials, or other secrets to git. Store them as environment variables - see [Using secrets](/deployments/using-secrets). ## Next steps Point your own domain at your Django app and remember to add it to `ALLOWED_HOSTS`. Set `DEBUG`, `SECRET_KEY`, and `ALLOWED_HOSTS` as environment variables. Learn more about provisioning and connecting managed databases. Understand how Miget shares compute across your apps. A full walkthrough including migrations and static files.