- Local Development: SQLite (file-based, zero setup)
- Production: PostgreSQL (scalable, robust)
- Environment-based: Automatic switching based on settings
- Connection Pooling: Optimized for production performance
- Apps Structure: All Django apps organized in
/appsdirectory - Settings Split: Environment-specific settings (base, local, production)
- Environment Configuration: Easy switching between development/production
- Logging: Structured logging configuration for different environments
- Security: Production-ready security settings and CORS configurationter Project
A comprehensive Django starter project with Django REST Framework, pre-configured with essential features for rapid development.
- Django 5.2.6 with Django REST Framework 3.15.2
- Custom User model with extended fields
- JWT/Token Authentication ready
- CORS configuration for frontend integration
- PostgreSQL and SQLite support
- Static and Media files configuration
- Comprehensive admin interface
- Custom User model with email as username
- User registration and login endpoints
- Password change functionality
- Profile management
- Token-based authentication
- Environment-based configuration with python-decouple
- Custom management commands
- Base models with timestamps and soft delete
- Custom permissions and pagination classes
- Whitenoise for static file serving
Django- Web frameworkdjangorestframework- API frameworkdjango-cors-headers- CORS handlingpython-decouple- Environment configurationPillow- Image processingdjango-filter- API filteringdj-database-url- Database URL parsingpsycopg2-binary- PostgreSQL adaptergunicorn- WSGI serverwhitenoise- Static file serving
git clone <your-repo-url>
cd django_starterpython -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activatepip install -r requirements.txtcp .env.example .envEdit .env file with your configurations:
DEBUG=True
SECRET_KEY=your-secret-key-here-change-in-production
ALLOWED_HOSTS=localhost,127.0.0.1
DJANGO_SETTINGS_MODULE=config.settings.local
DATABASE_URL=sqlite:///db.sqlite3
CORS_ALLOWED_ORIGINS=http://localhost:3000,http://127.0.0.1:3000Choose your environment configuration:
# For local development (default)
export DJANGO_SETTINGS_MODULE=config.settings.local
# For production
export DJANGO_SETTINGS_MODULE=config.settings.production
# Or use the helper script
./set_environment.shSQLite is used automatically for local development - no setup required!
python manage.py makemigrations
python manage.py migrateFor production, configure PostgreSQL in your environment:
# Set PostgreSQL connection in .env or environment
DATABASE_URL=postgres://username:password@host:port/database_name
# Example for local PostgreSQL
DATABASE_URL=postgres://postgres:mypassword@localhost:5432/django_starter
# Run with production settings
export DJANGO_SETTINGS_MODULE=config.settings.production
python manage.py migrate📚 See DATABASE_GUIDE.md for detailed database configuration instructions.
python manage.py create_superuser
# Or with custom credentials:
python manage.py create_superuser --email admin@yoursite.com --password yourpasswordpython manage.py runserverPOST /api/v1/auth/register/- User registrationPOST /api/v1/auth/login/- User loginPOST /api/v1/auth/logout/- User logoutGET /api/v1/auth/profile/- Get user profilePUT /api/v1/auth/profile/update/- Update user profilePOST /api/v1/auth/change-password/- Change passwordGET /api/v1/auth/list/- List users (admin only)
- Visit
/api/docs/for interactive API documentation
django_starter/
├── config/ # Django project configuration
│ ├── settings/ # Split settings configuration
│ │ ├── __init__.py # Settings package
│ │ ├── base.py # Base settings (common)
│ │ ├── local.py # Local development settings
│ │ └── production.py # Production settings
│ ├── urls.py # Main URL configuration
│ ├── wsgi.py # WSGI configuration
│ └── asgi.py # ASGI configuration
├── apps/ # All Django apps
│ ├── core/ # Core app with utilities
│ │ ├── management/ # Custom management commands
│ │ ├── models.py # Base models
│ │ ├── permissions.py # Custom permissions
│ │ ├── pagination.py # Pagination classes
│ │ └── utils.py # Utility functions
│ └── users/ # User management app
│ ├── models.py # Custom User model
│ ├── serializers.py # User serializers
│ ├── views.py # User API views
│ ├── urls.py # User URL patterns
│ └── admin.py # User admin configuration
├── static/ # Static files
├── media/ # Media files
├── templates/ # HTML templates
├── logs/ # Log files directory
├── requirements.txt # Python dependencies
├── .env.example # Environment variables example
├── .gitignore # Git ignore file
├── set_environment.sh # Environment switching script
├── deploy.sh # Deployment script
├── test_api.py # API testing script
├── quick_setup.sh # New project setup
├── Dockerfile # Docker configuration
├── docker-compose.yml # Docker Compose
└── manage.py # Django management script
import requests
response = requests.post('http://localhost:8000/api/v1/auth/register/', {
'username': 'testuser',
'email': 'test@example.com',
'password': 'testpass123',
'password_confirm': 'testpass123',
'first_name': 'Test',
'last_name': 'User'
})response = requests.post('http://localhost:8000/api/v1/auth/login/', {
'email': 'test@example.com',
'password': 'testpass123'
})
token = response.json()['token']headers = {'Authorization': f'Token {token}'}
response = requests.get('http://localhost:8000/api/v1/auth/profile/', headers=headers)Contains common settings shared across all environments:
- Installed apps configuration
- Middleware setup
- Templates configuration
- REST Framework settings
- DRF Spectacular configuration
Inherits from base and adds:
- Debug mode enabled
- SQLite database (default)
- Console email backend
- Development logging
- CORS allow all origins
Inherits from base and adds:
- Debug mode disabled
- Security headers and SSL settings
- PostgreSQL database support
- Email configuration (SMTP)
- Redis caching
- Structured logging
- Sentry integration (optional)
# Set environment variable
export DJANGO_SETTINGS_MODULE=config.settings.local
# Or use the helper script
./set_environment.sh
# Or set in .env file
DJANGO_SETTINGS_MODULE=config.settings.local- Create a new app in apps directory:
python manage.py startapp myapp apps/myapp - Add to
LOCAL_APPSinconfig/settings/base.py - Create URL patterns and include in main
urls.py
Extend the base models for automatic timestamps and soft delete:
from apps.core.models import BaseModel
class MyModel(BaseModel):
title = models.CharField(max_length=200)
# Automatically includes created_at, updated_at, is_deleted, deleted_atAdd new environment variables in .env and access them in settings:
from decouple import config
MY_SETTING = config('MY_SETTING', default='default_value')- Set
DEBUG=Falsein.env - Configure proper
SECRET_KEY - Set up PostgreSQL database
- Configure
ALLOWED_HOSTS - Use environment variables for sensitive data
Static files are handled by WhiteNoise. Run:
python manage.py collectstatic- Follow PEP 8
- Use meaningful variable names
- Add docstrings to functions and classes
- Write tests for new functionality
- Create feature branches from
main - Make descriptive commits
- Test before pushing
- Create pull requests for review
# Reset migrations
python manage.py migrate --fake-initial
python manage.py migrate# Make sure virtual environment is activated
source .venv/bin/activate- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is open source and available under the MIT License.
For questions or issues, please create an issue in the repository or contact the maintainers.
Happy Coding! 🚀