A production-ready Django REST Framework project template with Docker, PostgreSQL, and VS Code Dev Container support.
- 🐍 Django 5.1 with Django REST Framework
- 🐘 PostgreSQL database with Docker
- 🐳 Docker development and production setup
- 🔧 VS Code Dev Container for consistent development environment
- 👥 Custom User Model with email authentication
- 🏢 Multi-Tenant Support with tenant isolation
- 🔐 JWT Authentication with DRF SimpleJWT
- 🌐 CORS configured for frontend integration
- 📊 API Documentation with drf-spectacular (Swagger/OpenAPI)
- 🗑️ Soft Delete with django-safedelete
- 🎯 Base Models and ViewSets for rapid development
- 🚀 Production-ready Dockerfile with Gunicorn
- 📦 Auto-deployment ready with migrations
git clone <your-repo-url>
cd django-docker-postgress-drf-project-starter-with-vscode-devcontainer-and-deployment-config
cp .env.example .env
- Open this folder in VS Code
- When prompted, click "Reopen in Container"
- Or use Command Palette:
Dev Containers: Reopen in Container
- The devcontainer will automatically:
- Wait for PostgreSQL to be ready
- Install Python dependencies
- Apply existing migrations
# Create superuser
make superuser
# Start development server
make dev
- Development Server: http://localhost:8001
- Admin Panel: http://localhost:8001/admin
- API Documentation: http://localhost:8001/api/schema/swagger-ui/
- API Test Page: http://localhost:8001/
├── .devcontainer/ # VS Code Dev Container configuration
│ ├── devcontainer.json # Dev container settings
│ ├── docker-compose.yml # Development database setup
│ ├── wait-for-postgres.sh # Database readiness script
│ └── setup.sh # Automated environment setup
├── .vscode/ # VS Code launch configurations
├── core/ # Django project settings
├── apps/
│ ├── accounts/ # Custom user authentication
│ │ └── migrations/ # Database migrations (committed)
│ ├── tenants/ # Multi-tenant support
│ │ └── migrations/ # Database migrations (committed)
│ └── common/ # Shared models and utilities
├── templates/ # HTML templates
├── Dockerfile # Production Docker image
├── Dockerfile.dev # Development Docker image
├── docker-compose.prod.yml # Production compose
├── entrypoint.prod.sh # Production startup script
├── Makefile # Development commands and shortcuts
└── requirements.txt # Python dependencies
make help # Show all available commands
make dev # Start development server
make makemigrations # Create new migrations (when models change)
make migrate # Apply existing migrations
make shell # Open Django shell
make test # Run tests
make superuser # Create superuser
make lint # Run code linting
make format # Format code with black and isort
Important: Migration files are committed to the repository. Only create new migrations when you modify models.
# When you modify models (manual step):
make makemigrations
# To apply existing migrations (automated in devcontainer):
make migrate
# Check migration status:
python manage.py showmigrations
# Reset database (development only)
python manage.py flush
# Create and apply migrations
make makemigrations
make migrate
The devcontainer includes robust setup that:
- ✅ Waits for PostgreSQL to be ready before running Django commands
- ✅ Installs dependencies automatically
- ✅ Applies migrations from committed migration files
- ✅ Handles timing issues with database connectivity
wait-for-postgres.sh
: Ensures database is ready before running commandssetup.sh
: Handles dependency installation and migrations- Clean workflow: No migration generation in containers - only applies existing migrations
- Pre-configured extensions for Python development
- Django-specific settings and formatters
- Integrated debugging support
# Development
make build-dev # Build development image
# Production
make build-prod # Build production image
make prod-up # Start production environment
make prod-down # Stop production environment
make prod-logs # View production logs
make clean # Clean up Docker resources
# Production image
docker build -t your-app:latest -f Dockerfile .
# Development image
docker build -t your-app-dev:latest -f Dockerfile.dev .
# Database
DB_NAME=your_db_name
DB_USER=your_db_user
DB_PASSWORD=your_secure_password
DB_HOST=your_db_host
DB_PORT=5432
# Django
DJANGO_SECRET_KEY=your_very_secure_secret_key
DJANGO_DEBUG=False
DJANGO_ALLOWED_HOSTS=yourdomain.com,www.yourdomain.com
- ✅ Auto-migrations on container startup
- ✅ Static file collection with WhiteNoise
- ✅ Health checks and proper logging
- ✅ Non-root user for security
- ✅ Optimized multi-stage build
- Email-based authentication (no username)
- Located in
apps/accounts/models/users.py
- Includes first_name, last_name, and standard Django permissions
- JWT tokens via
rest_framework_simplejwt
- Session authentication for browsable API
- Custom permissions with tenant support
python manage.py startapp your_app_name apps/your_app_name
from apps.common.models.base import BaseModel, BaseModelWithTenant
class YourModel(BaseModelWithTenant):
name = models.CharField(max_length=100)
# Automatically includes: id, created_at, updated_at, created_by, updated_by, tenant
from apps.common.views.base_model_view import BaseModelViewSet
class YourViewSet(BaseModelViewSet):
# Automatically includes: tenant filtering, permissions, CRUD operations
pass
This template includes a complete multi-tenant system:
- Tenant Model: Complete organization management with contact info and settings
- User Limits: Configurable maximum users per tenant
- Tenant Admin: Full Django admin interface for tenant management
- API Endpoints: REST API for tenant CRUD operations
- Tenant Isolation: Models can inherit
BaseModelWithTenant
for automatic tenant filtering
GET /api/v1/tenants/
- List all tenantsPOST /api/v1/tenants/
- Create new tenant (admin only)GET /api/v1/tenants/{id}/
- Get tenant detailsPUT /api/v1/tenants/{id}/
- Update tenant (admin only)POST /api/v1/tenants/{id}/activate/
- Activate tenant (admin only)POST /api/v1/tenants/{id}/deactivate/
- Deactivate tenant (admin only)GET /api/v1/tenants/{id}/stats/
- Get tenant statistics
from apps.common.models import BaseModelWithTenant
class YourModel(BaseModelWithTenant):
name = models.CharField(max_length=100)
# Automatically includes tenant relationship and audit fields
from apps.tenants.mixins import TenantFilterMixin
class YourViewSet(TenantFilterMixin, ModelViewSet):
# Automatically filters by user's tenant
pass
Access interactive API documentation:
- Swagger UI:
/api/docs/
- OpenAPI Schema:
/api/schema/
- API Test Page:
/
(root URL)
- Fork the repository
- Create your feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
This project is licensed under the MIT License.
If you encounter any issues or have questions, please create an issue in the repository.