---
name: django-templates
description: Creates Django 6.0 HTML templates with partials, HTMX integration, and modern best practices. Use for template creation, refactoring, or HTMX endpoints.
argument-hint: [template-name] [--partial|--htmx|--base]
allowed-tools: Read, Write, Edit, Glob, Grep
---
# Django 6.0 HTML Templates
Generate production-ready Django 6.0.2 templates with Template Partials, HTMX integration, CSP support, and modern best practices for the league-planner project.
## When to Use
- Creating new HTML templates with Django 6.0 features
- Refactoring templates to use Template Partials
- Building HTMX-powered dynamic components
- Setting up base templates with proper block structure
- Implementing reusable template fragments
## Prerequisites
- Django 6.0+ installed
- Templates directory configured in settings
- For HTMX: `django-htmx` package (optional but recommended)
## Instructions
### Step 1: Analyze Request
Parse `$ARGUMENTS` to determine:
- **Template name**: The target template file
- **Type flag**:
- `--partial`: Create reusable partial fragments
- `--htmx`: HTMX-enabled template with partial endpoints
- `--base`: Base template with block structure
- (none): Standard template
### Step 2: Check Existing Templates
```bash
# Find existing templates in league-planner
find . -path "*/templates/*.html" -type f
```
Review the project's template structure and naming conventions.
### Step 3: Generate Template
Apply the appropriate pattern from the examples below.
---
## Django 6.0 Template Features
### Template Partials (NEW in 6.0)
Define reusable fragments without separate files:
```django
{# Define a partial #}
{% partialdef card %}
{{ title }}
{{ content }}
{% endpartialdef %}
{# Render the partial multiple times #}
{% partial card %}
{% partial card %}
```
**Inline Option** - Render immediately AND save for reuse:
```django
{% partialdef filter_controls inline %}
{% endpartialdef %}
{# Can still reuse later #}
{% partial filter_controls %}
```
### Accessing Partials from Views (HTMX Pattern)
Render only a specific partial:
```python
# views.py
from django.shortcuts import render
def update_component(request, pk):
obj = MyModel.objects.get(pk=pk)
# Render ONLY the partial named "item_row"
return render(request, "myapp/list.html#item_row", {"item": obj})
```
### forloop.length (NEW in 6.0)
Access total loop count:
```django
{% for item in items %}