What Django Deployment
Is Really About
James Walters
Is Django Hard to Deploy?
🤔️
James Walters - james.walters.click
The Penguin in the Room
James Walters - james.walters.click
Four Main Concerns
(and a couple of other things)
James Walters - james.walters.click
Static Files 📁️
James Walters - james.walters.click
But {% static %}, right?
James Walters - james.walters.click
index.html
about.html
news.html
posts.html
www.yourwebsite.com
Apache / nginx
James Walters - james.walters.click
template.html
www.yourwebsite.com
Apache / nginx
Database
Django
James Walters - james.walters.click
template.html
www.yourwebsite.com
Apache / nginx
Database
Django
style.css
STATIC_ROOT
script.js
. . .
James Walters - james.walters.click
Static Files
James Walters - james.walters.click
But Whitenoise, right?
James Walters - james.walters.click
But Whitenoise, right?
James Walters - james.walters.click
https://realpython.com/django-nginx-gunicorn/#serving-static-files-directly-with-nginx
What about user uploaded files?
James Walters - james.walters.click
Database 💾️
James Walters - james.walters.click
But SQLite, right?
James Walters - james.walters.click
https://www.youtube.com/watch?v=yTicYJDT1zE
But SQLite, right?
James Walters - james.walters.click
settings.py
…
DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": "mydatabase",
}
}
…
…
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql'
'NAME': 'mydatabase',
'USER': 'mydatabaseuser',
'PASSWORD': 'mypassword',
'HOST': '127.0.0.1',
'PORT': '5432',
}
}
…
James Walters - james.walters.click
Database
James Walters - james.walters.click
WSGI Server 🥃️
James Walters - james.walters.click
But manage.py runserver, right?
James Walters - james.walters.click
www.yourwebsite.com
Apache / nginx
Django
James Walters - james.walters.click
www.yourwebsite.com
Apache / nginx
Django
WSGI
Server
Gunicorn
Waitress
uWSGI
wsgi.py
James Walters - james.walters.click
Web Server 🕸️
James Walters - james.walters.click
Web Server
James Walters - james.walters.click
https://realpython.com/django-nginx-gunicorn/
But do you even need to configure the web server yourself? 🤔️
It depends on your deployment choice…
James Walters - james.walters.click
VPS
James Walters - james.walters.click
PaaS
James Walters - james.walters.click
(Soft) Verdict?
James Walters - james.walters.click
✅️ PaaS
James Walters - james.walters.click
Django's Deployment Checklist ✅️
James Walters - james.walters.click
Django’s Deployment Checklist
James Walters - james.walters.click
manage.py check --deploy
$ python manage.py check --deploy
System check identified some issues:
WARNINGS:
?: (security.W004) You have not set a value for the SECURE_HSTS_SECONDS setting. If your entire site is served only over SSL, you may want to consider setting a value and enabling HTTP Strict Transport Security. Be sure to read the documentation first; enabling HSTS carelessly can cause serious, irreversible problems.
?: (security.W008) Your SECURE_SSL_REDIRECT setting is not set to True. Unless your site should be available over both SSL and non-SSL connections, you may want to either set this setting True or configure a load balancer or reverse-proxy server to redirect all connections to HTTPS.
?: (security.W009) Your SECRET_KEY has less than 50 characters, less than 5 unique characters, or it's prefixed with 'django-insecure-' indicating that it was generated automatically by Django. Please generate a long and random value, otherwise many of Django's security-critical features will be vulnerable to attack.
?: (security.W012) SESSION_COOKIE_SECURE is not set to True. Using a secure-only session cookie makes it more difficult for network traffic sniffers to hijack user sessions.
?: (security.W016) You have 'django.middleware.csrf.CsrfViewMiddleware' in your MIDDLEWARE, but you have not set CSRF_COOKIE_SECURE to True. Using a secure-only CSRF cookie makes it more difficult for network traffic sniffers to steal the CSRF token.
?: (security.W018) You should not have DEBUG set to True in deployment.
?: (security.W020) ALLOWED_HOSTS must not be empty in deployment.
James Walters - james.walters.click
django-simple-deploy 😃️
James Walters - james.walters.click
django-simple-deploy
James Walters - james.walters.click
https://django-simple-deploy.readthedocs.io/en/latest/
django-simple-deploy
James Walters - james.walters.click
https://django-simple-deploy.readthedocs.io/en/latest/
django-production 🏭️
James Walters - james.walters.click
django-production
James Walters - james.walters.click
https://github.com/lincolnloop/django-production
django-production
James Walters - james.walters.click
https://github.com/lincolnloop/django-production
From README:
The Whale in the Room
Docker Pros
Docker Cons
Wrapping Up 🎁️
See my blog james.walters.click for links to these slides, and the resources mentioned.
Github: github.com/iamjameswalters
Mastodon: @jameswalters@fosstodon.org
Email: jameswalters@hey.com
Thank You!