You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
3 days ago | |
|---|---|---|
| apps | 3 days ago | |
| centrifugo | 4 weeks ago | |
| config | 3 days ago | |
| dynamic_preferences | 4 weeks ago | |
| locale | 4 weeks ago | |
| nginx | 4 weeks ago | |
| templates | 3 days ago | |
| test_media | 3 weeks ago | |
| utils | 3 days ago | |
| .dockerignore | 4 weeks ago | |
| .env.dev | 3 weeks ago | |
| .env.example | 4 weeks ago | |
| .env.prod | 4 weeks ago | |
| .gitignore | 4 weeks ago | |
| Dockerfile | 4 weeks ago | |
| Dockerfile.prod | 4 weeks ago | |
| README.md | 4 weeks ago | |
| db.sqlite3.backup | 4 days ago | |
| docker-compose.prod.yml | 4 weeks ago | |
| docker-compose.yml | 4 weeks ago | |
| dump.rdb | 4 days ago | |
| entrypoint.sh | 4 weeks ago | |
| manage.py | 3 weeks ago | |
| package-lock.json | 4 weeks ago | |
| package.json | 4 weeks ago | |
| requirements.txt | 3 weeks ago | |
| schema.yml | 4 days ago | |
| tailwind.config.js | 4 weeks ago | |
README.md
Django Backend Starter Template
A modern, production-ready, batteries-included Django backend template built for rapid application development.
๐ Tech Stack
- Framework: Django 5.0+
- API Engine: Django REST Framework (DRF)
- Admin Interface: Django Unfold (Tailwind-based modern UI)
- Database: PostgreSQL
- Caching & Broker: Redis
- Task Queue: Celery & Celery Beat
- API Documentation: Swagger UI & ReDoc via
drf-yasg - Static Assets: WhiteNoise
- Containerization: Docker & Docker Compose
๐ Key Features
- Custom User Authentication (
apps/account):- Email-based authentication (no cumbersome usernames).
- Profile management with avatar, phone number, and metadata.
- Built-in
LoginHistoryandLocationHistorytracking. - Standard authentication endpoints (Register, Login, Token Exchange, Password Reset, Profile Update).
- Clean group and role-based permissions.
- Modern Admin Panel (
utils/admin.py& Django Unfold):- Modern Tailwind styling with dark/light mode.
- Dynamic Dashboard KPI statistics.
- Responsive sidebar with configurable navigation.
- Interactive API Documentation (
apps/api):- Live Swagger UI at
/swagger/and ReDoc at/redoc/. - Token authentication banner for test requests.
- Health check endpoint at
/api/v1/health/. - Mobile app release versioning (
AppVersion).
- Live Swagger UI at
- Runtime Dynamic Preferences (
dynamic_preferences/):- Editable site-wide settings directly from the admin panel (site title, contact email, maintenance mode).
- Production Ready:
- Multi-stage Dockerfile and Docker Compose setup.
- Nginx reverse proxy configuration.
- Pre-configured Gzip compression, security headers, and media streaming.
๐ Project Structure
โโโ apps/
โ โโโ account/ # Custom User, authentication, profile, notifications
โ โ โโโ admin/ # Unfold user and group admin
โ โ โโโ migrations/ # Initial schema migrations
โ โ โโโ models/ # User, LoginHistory, Notification models
โ โ โโโ serializers/ # DRF serializers for user & auth
โ โ โโโ views/ # Register, login, profile, notification views
โ โ โโโ urls.py # Account API endpoints
โ โโโ api/ # Core API utilities, versions, health checks
โ โโโ admin/ # Version & support admin
โ โโโ migrations/ # Initial schema migrations
โ โโโ models/ # AppVersion, SupportMessage
โ โโโ serializers/ # API serializers
โ โโโ views/ # HealthCheck, AppVersion, Swagger views
โ โโโ urls.py # Core API routes
โโโ config/
โ โโโ settings/
โ โ โโโ base.py # Base Django settings
โ โ โโโ develop.py # Development settings
โ โ โโโ production.py # Production settings
โ โ โโโ test.py # Test settings
โ โโโ celery.py # Celery worker configuration
โ โโโ urls.py # Root URL configuration
โ โโโ wsgi.py # WSGI entry point
โ โโโ asgi.py # ASGI entry point
โโโ dynamic_preferences/ # In-tree runtime preferences registry
โโโ nginx/
โ โโโ app.conf # Nginx reverse proxy config
โโโ static/ # Static CSS and JS assets
โโโ templates/
โ โโโ admin/ # Unfold admin dashboard & overrides
โ โโโ swagger/ # Custom Swagger UI templates
โโโ utils/ # Reusable helper modules
โ โโโ admin.py # Unfold AdminSite and dashboard callbacks
โ โโโ exceptions.py # DRF custom exception handler
โ โโโ image_compression.py # Image optimization
โ โโโ pagination.py # Standard REST pagination
โ โโโ redis.py # Redis token and cache helpers
โโโ .env.example # Environment variables template
โโโ .env.dev # Local development env defaults
โโโ docker-compose.yml # Docker compose configuration
โโโ Dockerfile # Docker build file
โโโ manage.py # Django CLI
โโโ requirements.txt # Python dependencies
๐ ๏ธ Quick Start
1. Using Docker (Recommended)
-
Clone or copy the template:
git init my-project cd my-project -
Setup environment variables:
cp .env.example .env.dev -
Build and start services:
docker compose up -d --build -
Run migrations and create superuser:
docker compose exec web python manage.py migrate docker compose exec web python manage.py createsuperuser -
Access the app:
- Admin Panel: http://localhost:8000/admin/
- Swagger Docs: http://localhost:8000/swagger/
- Health Check: http://localhost:8000/api/v1/health/
2. Local Python Environment
-
Create and activate a virtual environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate -
Install dependencies:
pip install -r requirements.txt -
Configure environment:
cp .env.example .env # Edit .env with your local PostgreSQL and Redis credentials -
Apply migrations:
python manage.py migrate python manage.py createsuperuser -
Run the development server:
python manage.py runserver
๐ Environment Variables Reference
| Variable | Description | Default |
|---|---|---|
DJANGO_SECRET_KEY |
Unique Django secret key | (Required in production) |
DJANGO_DEBUG |
Enable debug mode | True |
DJANGO_ALLOWED_HOSTS |
Comma-separated allowed hostnames | 127.0.0.1,localhost |
POSTGRES_DB |
PostgreSQL database name | app_db |
POSTGRES_USER |
PostgreSQL user | postgres |
POSTGRES_PASSWORD |
PostgreSQL password | postgres |
POSTGRES_HOST |
PostgreSQL host | postgres / localhost |
POSTGRES_PORT |
PostgreSQL port | 5432 |
REDIS_URL |
Redis connection URL | redis://redis:6379/0 |
SENTRY_DSN |
Sentry error tracking DSN | (Optional) |
๐ก API Endpoints Overview
- Auth & Account:
POST /api/v1/account/register/- User registrationPOST /api/v1/account/login/- User login & token generationGET /api/v1/account/profile/- Authenticated user profilePUT /api/v1/account/profile/update/- Update profilePOST /api/v1/account/recover/- Request password recoveryPOST /api/v1/account/reset/- Reset password
- System & Utilities:
GET /api/v1/health/- Server health statusGET /api/v1/version/- Latest mobile application versionPOST /api/v1/contact-us/- Submit support/contact message
- Documentation:
/swagger/- Interactive Swagger UI/redoc/- ReDoc API documentation