A comprehensive training resource for teams transitioning from jQuery/AJAX to HTMX, built with Django.
License: MIT
This project provides side-by-side comparisons of jQuery/AJAX and HTMX implementations for common web interaction patterns. Perfect for research software engineering teams looking to modernize their Django applications.
- 9 Interactive Patterns: Form submissions, live search, infinite scroll, modals, dynamic lists, dependent dropdowns, polling, interactive maps, and WebSocket notifications
- Side-by-Side Comparisons: See jQuery and HTMX implementations together
- HTMX Deep Dive: Detailed explanations and best practices
- Hands-On Exercises: Practice building real-world features with guided challenges
- Comprehensive Documentation: Guides covering concepts, comparisons, and common pitfalls
- Sample Data: Pre-populated examples ready to explore
- Form Submissions - Contact form with inline validation and success messages
- Live Search/Filtering - Search contacts with real-time results
- Infinite Scroll/Lazy Loading - Product list with automatic pagination
- Modal Dialogs - Open modals with server-rendered content
- Dynamic List Operations - Todo list with add/remove/toggle functionality
- Dependent Dropdowns - Country → State → City cascading selects
- Polling/Auto-refresh - Live status dashboard with automatic updates
- Interactive Maps (Leaflet) - Filterable location markers with free OpenStreetMap tiles (no API token required)
- WebSocket/Real-time Notifications - Live notifications using WebSockets with HTMX extensions
In addition to the interactive examples, the project includes practical exercises organized by difficulty level:
- Beginner Exercises: Start your HTMX journey with foundational patterns
- Intermediate Exercises: Level up with more complex real-world scenarios
- Advanced Exercises: Master advanced techniques and complex integrations
Each exercise provides a prompt, requirements, starter templates, and hints to help you build features hands-on. No answers provided - the goal is learning through experimentation!
The project includes example environment files in .envs/.local/ that work out of the box for local development:
.envs/.local/.django- Django configuration.envs/.local/.postgres- PostgreSQL configuration with safe defaults
These files are already in the repository and require no changes for local development. For production deployments, you'll need to create .envs/.production/ files with your actual secrets (see Production section below).
-
Build the Docker images:
docker compose -f docker-compose.local.yml build
-
Start the containers:
docker compose -f docker-compose.local.yml up -d
-
Load sample data:
# Load curated fixture (recommended for demos) docker compose -f docker-compose.local.yml run --rm django python manage.py loaddata sample_data # OR generate random data (larger dataset) docker compose -f docker-compose.local.yml run --rm django python manage.py create_sample_data
-
Create a superuser (optional - not required):
docker compose -f docker-compose.local.yml run --rm django python manage.py createsuperuser
Your application will be running at http://localhost:8000
Once the server is running, visit:
- http://localhost:8000/ - Home page with overview
- http://localhost:8000/examples/ - Examples landing page
- http://localhost:8000/examples/comparison/ - Side-by-side jQuery vs HTMX comparisons
- http://localhost:8000/examples/htmx-deep-dive/ - HTMX-focused deep dive with explanations
- http://localhost:8000/exercises/ - Hands-on exercises for practice
Comprehensive guides are available in the docs/ directory:
- HTMX_GUIDE.md - Complete HTMX reference with attributes, patterns, and best practices
- COMPARISON_GUIDE.md - Detailed code-by-code comparisons with analysis
- GOTCHAS.md - Common pitfalls and how to avoid them
Based on the examples in this project:
- 66% less code on average compared to jQuery/AJAX
- Simpler maintenance - less JavaScript to manage
- Server-driven UI - single source of truth
- Progressive enhancement - works without JavaScript
- Better separation of concerns - HTML for structure, server for logic
htmx-demo/
├── config/ # Django settings and main URL config
├── docs/ # Comprehensive documentation
│ ├── HTMX_GUIDE.md
│ ├── COMPARISON_GUIDE.md
│ └── GOTCHAS.md
├── htmx_demo/
│ ├── examples/ # Main examples app
│ │ ├── models.py # Data models for demonstrations
│ │ ├── views.py # jQuery and HTMX view implementations
│ │ ├── urls.py # URL routing
│ │ └── README.md # Detailed examples documentation
│ ├── exercises/ # Hands-on practice exercises
│ │ ├── views.py # Exercise content and routing
│ │ └── README.md # Exercise documentation
│ ├── static/
│ │ └── css/
│ │ ├── project.css # Global styling
│ │ └── examples.css # Styling for examples
│ └── templates/
│ ├── examples/ # All example templates
│ │ ├── index.html
│ │ ├── comparison.html
│ │ ├── htmx_deep_dive.html
│ │ └── partials/ # HTML fragments for HTMX
│ └── exercises/ # Exercise templates
└── README.md # This file
- Start with the comparison page to show side-by-side implementations
- Open browser DevTools to demonstrate request/response differences
- Walk through the code to explain the patterns
- Use the deep dive page for detailed explanations
- Assign exercises for hands-on practice
- Reference the documentation for comprehensive coverage
- Explore the interactive examples to see patterns in action
- View page source to see HTMX attributes in action
- Open DevTools Network tab to observe requests
- Read the documentation to understand concepts
- Complete exercises to build real-world features
- Experiment with modifications
- Apply patterns to your own projects
# With uv
uv run pytest
# With Docker
docker compose -f docker-compose.local.yml run --rm django pytest# Run linter
uv run ruff check .
# Format code
uv run ruff format .
# Type checking
uv run mypy .For production deployments, you'll need to create environment files in .envs/.production/:
-
Copy the example files:
cp .envs/.production/.django.example .envs/.production/.django cp .envs/.production/.postgres.example .envs/.production/.postgres
-
Edit
.envs/.production/.djangowith your production settings:- Generate a secure
DJANGO_SECRET_KEY(50+ characters) - Set your
DJANGO_ALLOWED_HOSTS - Configure email settings (MAILGUN_API_KEY, etc.)
- Set a secure, random
DJANGO_ADMIN_URL
- Generate a secure
-
Edit
.envs/.production/.postgreswith secure database credentials
Note: The actual .django and .postgres files are gitignored and will never be committed. Only the .example templates are in the repository. Keep your secrets safe!
This project is designed for educational purposes. Feel free to:
- Add new examples
- Improve existing patterns
- Enhance documentation
- Report issues
- Submit pull requests