Single-file deploy Django to a generic Ubuntu host

Full-automatic, copy-paste Nginx/Gunicorn/Let’s Encrypt HTTPS set up in minutes

Project set up

pip install --user pipenv
mkdir mysite && cd mysite/
pipenv install django django-environ --python=python3.7
pipenv run django-admin startproject config .
├── config/
│ ├──
│ ├──
│ ├──
│ └──
├── Pipfile
└── Pipfile.lock
import os
import environ
from pathlib import Path
# Build paths inside the project
BASE_DIR = Path(__file__).resolve(strict=True).parents[1]
# configure django-environ to run in dev mode without .env file
env = environ.Env(
DATABASE_URL=(str, 'sqlite:///sqlite.db'),
DOMAIN_NAME=(str, ''),
DEBUG=(bool, False),
SECRET_KEY=(str, '{{ secret_key }}'),
env.read_env(BASE_DIR / '.env') if os.path.exists(BASE_DIR / '.env') else None
'default': env.db()
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

Let’s deploy

pipenv install -d ansible
pipenv run ansible-playbook -i, -u root deploy.yml

What you’ve just done

Have a problem?

FAQ startproject --template= mysite

Reusable workflow library #django #python

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store