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 .
mysite/
├── config/
│ ├── __init__.py
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
├── manage.py
├── 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, '127.0.0.1'),
DEBUG=(bool, False),
SECRET_KEY=(str, '{{ secret_key }}'),
)
env.read_env(BASE_DIR / '.env') if os.path.exists(BASE_DIR / '.env') else None
DEBUG = env.bool('DEBUG')ALLOWED_HOSTS = [env.str('DOMAIN_NAME')]SECRET_KEY = env.str('SECRET_KEY')DATABASES = {
'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

ssh root@yourdomain.com
pipenv install -d ansible
pipenv run ansible-playbook -i yourdomain.com, -u root deploy.yml

What you’ve just done

Have a problem?

FAQ

django-admin.py startproject --template=https://github.com/viewflow/django-skinny-deploy/archive/template.zip mysite

Reusable workflow library #django #python http://viewflow.io

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