Configuration¶
django-prodserver is configured through the PRODUCTION_PROCESSES setting.
Basic Structure¶
PRODUCTION_PROCESSES = {
"process_name": {
"BACKEND": "path.to.backend.class",
"APP": "optional.app.path", # Required for Celery
"ARGS": {"arg_name": "value"},
}
}
Configuration Keys¶
BACKEND (Required)¶
Python import path to the backend class:
"BACKEND": "django_prodserver.backends.servers.gunicorn.GunicornServer"
Available backends:
APP (Celery only)¶
Path to Celery app instance:
"APP": "myproject.celery.app"
ARGS¶
Arguments passed to the backend, converted to CLI flags:
"ARGS": {
"bind": "0.0.0.0:8000", # --bind=0.0.0.0:8000
"workers": "4", # --workers=4
}
How ARGS Translation Works:
Dictionary keys become argument names (with
--prefix)Dictionary values become argument values (with
=separator)Arguments are passed directly to the underlying backend
Example Translation:
# Settings configuration
PRODUCTION_PROCESSES = {
"web": {
"BACKEND": "django_prodserver.backends.servers.gunicorn.GunicornServer",
"ARGS": {
"bind": "0.0.0.0:8000",
"workers": "4",
"worker-class": "sync",
"timeout": "60"
}
}
}
# Translates to CLI command:
# gunicorn --bind=0.0.0.0:8000 --workers=4 --worker-class=sync --timeout=60
See Backend Reference for backend-specific ARGS.
Complete Configuration Examples¶
Single Web Server¶
Basic Gunicorn web server:
PRODUCTION_PROCESSES = {
"web": {
"BACKEND": "django_prodserver.backends.servers.gunicorn.GunicornServer",
"ARGS": {"bind": "0.0.0.0:8000", "workers": "4"},
}
}
Web + Worker + Beat¶
PRODUCTION_PROCESSES = {
"web": {
"BACKEND": "django_prodserver.backends.servers.gunicorn.GunicornServer",
"ARGS": {"bind": "0.0.0.0:8000", "workers": "4"},
},
"worker": {
"BACKEND": "django_prodserver.backends.workers.celery.CeleryWorker",
"APP": "myproject.celery.app",
"ARGS": {"concurrency": "4", "loglevel": "info"},
},
"beat": {
"BACKEND": "django_prodserver.backends.workers.celery.CeleryBeat",
"APP": "myproject.celery.app",
"ARGS": {"loglevel": "info"},
},
}
Environment Variables¶
import os
PRODUCTION_PROCESSES = {
"web": {
"BACKEND": "django_prodserver.backends.servers.gunicorn.GunicornServer",
"ARGS": {
"bind": f"0.0.0.0:{os.getenv('PORT', '8000')}",
"workers": os.getenv('WEB_WORKERS', '4'),
},
}
}
Best Practices¶
Use environment-specific settings files (
settings_dev.py,settings_prod.py)Use environment variables for deployment-specific values
Start with
workers = CPU_count * 2 + 1and tune based on monitoringSet appropriate timeouts for your application
Use process supervision (systemd, Docker) for automatic restarts
Common Mistakes¶
Warning
Port conflicts: Each process needs a unique port
Missing APP: Celery backends require the
APPkeyWrong BACKEND path: Use full import path including class name
Missing backend package: Install gunicorn, celery, etc.
API Documentation¶
These are the available settings.
All attributes prefixed PRODUCTION_* can be overridden from your Django
project’s settings module by defining a setting with the same name.
Next Steps¶
Backend Reference - Backend-specific ARGS
Usage - Running processes
Troubleshooting - Common issues