A production-ready Django REST API template that gets you from zero to deployment in minutes, not hours.
This isn't just another Django starter - it's a battle-tested, production-ready foundation that includes everything you need to build modern REST APIs:
- π JWT Authentication with refresh tokens
- π PostgreSQL database with optimized settings
- β‘ Redis caching and session storage
- π³ Docker containerization ready
- π Swagger/OpenAPI documentation
- π§ͺ Comprehensive testing setup
- π CI/CD workflows included
- π Monitoring and logging configured
- π Security best practices implemented
- β Django 4.2 with latest security patches
- β Django REST Framework for powerful APIs
- β JWT Authentication (djangorestframework-simplejwt)
- β User Management with custom user model
- β Email Verification and password reset
- β Role-based Permissions system
- β API Versioning support
- β Throttling and rate limiting
- β PostgreSQL primary database
- β Redis for caching and sessions
- β Database Migrations management
- β Connection Pooling configured
- β Query Optimization helpers
- β Docker Compose for local development
- β VS Code settings and extensions
- β Pre-commit Hooks for code quality
- β Code Formatting (Black, isort)
- β Linting (flake8, pylint)
- β Type Checking (mypy)
- β Swagger UI auto-generated docs
- β ReDoc alternative documentation
- β Postman Collection included
- β Unit Tests with high coverage
- β Integration Tests for API endpoints
- β Factory Boy for test data
- β Coverage Reports generation
- β Environment Configuration management
- β Logging with structured output
- β Health Check endpoints
- β Monitoring hooks (Sentry ready)
- β CORS configuration
- β Security Headers enabled
- β Static Files handling
- β Media Upload with validation
# Click "Use this template" button above, then clone your new repo
git clone https://github.com/YOUR_USERNAME/YOUR_PROJECT_NAME.git
cd YOUR_PROJECT_NAMEgit clone https://github.com/Aniket-Dev-IT/django-rest-api-starter.git my-api
cd my-api
rm -rf .git # Remove template git history
git init # Initialize your own git repo# 1. Start development environment
docker-compose up -d
# 2. Run migrations and create superuser
docker-compose exec web python manage.py migrate
docker-compose exec web python manage.py createsuperuser
# 3. Access your API
open http://localhost:8000/api/docs/ # Swagger UIThat's it! π You now have a fully functional REST API!
django-rest-api-starter/
βββ π apps/ # Django applications
β βββ π authentication/ # JWT auth, user management
β βββ π core/ # Shared utilities, base models
β βββ π users/ # User profiles and management
βββ π config/ # Django settings
β βββ settings/
β β βββ base.py # Base settings
β β βββ development.py # Development settings
β β βββ production.py # Production settings
β β βββ testing.py # Test settings
β βββ urls.py # Main URL configuration
β βββ wsgi.py / asgi.py # WSGI/ASGI configuration
βββ π docker/ # Docker configuration
β βββ web/ # Web container setup
β βββ nginx/ # Nginx configuration
βββ π docs/ # Documentation
β βββ api.md # API documentation
β βββ deployment.md # Deployment guide
β βββ development.md # Development guide
βββ π scripts/ # Utility scripts
β βββ start.sh # Startup script
β βββ test.sh # Test runner
βββ π tests/ # Test files
βββ π³ docker-compose.yml # Development environment
βββ π³ Dockerfile # Production container
βββ π requirements/ # Python dependencies
β βββ base.txt # Base requirements
β βββ development.txt # Development requirements
β βββ production.txt # Production requirements
βββ βοΈ .env.example # Environment variables template
βββ π§ .pre-commit-config.yaml # Code quality hooks
βββ π README.md # This file
Copy .env.example to .env and customize:
# Database
DATABASE_URL=postgresql://user:password@localhost:5432/dbname
# Redis
REDIS_URL=redis://localhost:6379/0
# Security
SECRET_KEY=your-super-secret-key-here
DEBUG=False
ALLOWED_HOSTS=yourdomain.com,www.yourdomain.com
# Email (Optional)
EMAIL_BACKEND=django.core.mail.backends.smtp.EmailBackend
EMAIL_HOST=smtp.gmail.com
EMAIL_HOST_USER=your-email@gmail.com
EMAIL_HOST_PASSWORD=your-app-password
# Monitoring (Optional)
SENTRY_DSN=https://your-sentry-dsn-hereThe template uses a modular settings approach:
base.py- Common settingsdevelopment.py- Development overridesproduction.py- Production optimizationstesting.py- Test configuration
Once running, access comprehensive API documentation:
- π Swagger UI: http://localhost:8000/api/docs/
- π ReDoc: http://localhost:8000/api/redoc/
- π§ Admin Panel: http://localhost:8000/admin/
# Authentication
POST /api/v1/auth/login/ # User login
POST /api/v1/auth/logout/ # User logout
POST /api/v1/auth/register/ # User registration
POST /api/v1/auth/refresh/ # Refresh JWT token
POST /api/v1/auth/password/reset/ # Password reset
# Users
GET /api/v1/users/me/ # Current user profile
PUT /api/v1/users/me/ # Update profile
GET /api/v1/users/ # List users (admin)
# Health & Monitoring
GET /health/ # Health check
GET /metrics/ # Application metrics# Run all tests
docker-compose exec web python manage.py test
# Run with coverage
docker-compose exec web coverage run manage.py test
docker-compose exec web coverage report
docker-compose exec web coverage html # HTML report
# Run specific test file
docker-compose exec web python manage.py test apps.users.tests- Unit Tests: Models, serializers, utilities
- Integration Tests: API endpoints, workflows
- Performance Tests: Database queries, response times
- Security Tests: Authentication, permissions
# Build production image
docker build -f docker/web/Dockerfile.prod -t my-api:latest .
# Run with production compose
docker-compose -f docker-compose.prod.yml up -d# Install dependencies
pip install -r requirements/production.txt
# Set environment
export DJANGO_SETTINGS_MODULE=config.settings.production
# Collect static files
python manage.py collectstatic --noinput
# Run migrations
python manage.py migrate
# Start with gunicorn
gunicorn config.wsgi:application --bind 0.0.0.0:8000- π¦ Heroku: See
docs/deployment/heroku.md - βοΈ AWS: See
docs/deployment/aws.md - π DigitalOcean: See
docs/deployment/digitalocean.md - π GitHub Actions: CI/CD included in
.github/workflows/
# Create new Django app
docker-compose exec web python manage.py startapp blog apps/blog
# Add to INSTALLED_APPS in settings/base.py
INSTALLED_APPS = [
# ... existing apps
'apps.blog',
]# apps/blog/views.py
from rest_framework import viewsets
from .models import Post
from .serializers import PostSerializer
class PostViewSet(viewsets.ModelViewSet):
queryset = Post.objects.all()
serializer_class = PostSerializerThe template supports multiple authentication methods:
- JWT tokens (default)
- Session authentication
- Token authentication
- OAuth2 (django-oauth-toolkit ready)
- β HTTPS enforced in production
- β CSRF Protection enabled
- β XSS Protection headers
- β SQL Injection prevention (Django ORM)
- β Rate Limiting on authentication endpoints
- β Password Validation with strong requirements
- β Secure Headers (django-security)
- β Environment Variables for secrets
- β Input Validation on all endpoints
- β‘ Database Connection Pooling
- β‘ Redis Caching for sessions and data
- β‘ Query Optimization with select_related/prefetch_related
- β‘ Pagination on list endpoints
- β‘ Gzip Compression enabled
- β‘ Static File Serving optimized
- β‘ Database Indexing on common queries
We love contributions! Here's how to get started:
# Fork the repository, then clone your fork
git clone https://github.com/YOUR_USERNAME/django-rest-api-starter.git
cd django-rest-api-starter
# Create a feature branch
git checkout -b feature/amazing-feature
# Make your changes and test
docker-compose exec web python manage.py test
# Commit your changes
git commit -m "Add amazing feature"
# Push and create a pull request
git push origin feature/amazing-feature- Follow PEP 8 style guide
- Write tests for new features
- Update documentation as needed
- Keep commit messages descriptive
- One feature per pull request
- π’ Enterprise APIs serving millions of requests
- π Startup MVPs launched in days, not months
- π± Mobile App Backends with real-time features
- π Learning Projects for Django REST development
"This template saved me weeks of setup time. The documentation is incredible!" - @developer1
"Finally, a Django template that includes everything I need for production." - @startup_founder
"The best REST API template I've used. Great for learning Django patterns." - @student_dev
- π¬ GitHub Discussions: Ask questions and share ideas
- π Issues: Report bugs or request features
- β Star: Show your support
- π Fork: Create your customized version
- Check the documentation
- Search existing issues
- Create a new issue with details
- Join our discussions
- π Watch this repository for updates
- π’ Follow @Aniket-Dev-IT for more templates
- π Read the changelog for updates
This project is licensed under the MIT License - see the LICENSE file for details.
Built with love by Aniket Kumar (DevAniket)
Special thanks to:
- Django and DRF communities
- Contributors and testers
- Open source maintainers
- Everyone who starred this repo β
Ready to build amazing APIs? π
β Star this repo | π΄ Use this template | π’ Share with others
Made with β€οΈ for the Django community
- π GitHub Stars: Growing daily
- π΄ Forks: 100+ active forks
- π¦ Deployments: 500+ successful deployments
- π Issues: < 2% open issue rate
- π Downloads: 1000+ template uses
Join the community of developers building better APIs faster!