This hands-on guide builds and verifies How to Build a Django Application with PostgreSQL on Ubuntu 24.04 using an isolated, reproducible Python environment.
1. Create an isolated project
mkdir -p python-lab
cd python-lab
python3 -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip
python -m pip install django psycopg[binary]
Record the interpreter and dependencies before changing the application. Use python -m pip so packages are installed into the selected virtual environment.
2. Implement and run
django-admin startproject config .
python manage.py startapp inventory
python manage.py makemigrations
python manage.py migrate
Keep transport, configuration, business rules, and persistence in separate modules. Validate all environment and network input at the application boundary, set finite timeouts, and return actionable errors without exposing stack traces or credentials.
3. Verify the result
python manage.py check --deploy
A running process is not enough: verify the real request, file, database operation, worker state, or deployment rollout. Capture logs and expected output for repeatable operations.
4. Troubleshooting
Confirm the active interpreter with python -c "import sys; print(sys.executable)". Then inspect dependency versions, environment variables, permissions, listening addresses, service logs, and upstream connectivity. Change one variable at a time and retest.
Production checklist
- Supported Python and dependency versions are recorded.
- Secrets remain outside code, images, logs, and shell history.
- Validation, authorization, limits, timeouts, retries, and graceful shutdown are explicit.
- Tests and health checks cover success and failure paths.
- Backups, monitoring, security updates, rollback, and resource limits are tested.
Reference: official documentation.