.cursor/skills/htmx-patterns/SKILL.md
HTMX patterns for Django including partial templates, hx-* attributes, and dynamic UI without JavaScript. Use when building interactive UI, handling AJAX requests, or creating dynamic components.
npx skillsauth add AngelDann/app-comisions-dist htmx-patternsInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
_partial.html files for HTMX responsesAlways include loading indicators
hx-indicator to show loading states during requests<button hx-get="/data/" hx-indicator="#spinner">Load</button>Always provide user feedback
Handle errors gracefully
Always detect HTMX requests
request.headers.get("HX-Request") to detect HTMX requestsif request.headers.get("HX-Request"): return render(request, "_partial.html", context)Always return partials for HTMX
_partial.html templates, not full pages with base.htmlAlways validate request.method
request.method == "POST" before processing form dataCSRF is already configured globally
hx-headers on <body> - no need to add CSRF tokens to individual formsNaming convention
_partial.html (underscore prefix)page.html (no prefix)posts/list.html (full page) includes posts/_list.html (partial)Structure
base.html and includes partialKeep partials focused
Check the HX-Request header to detect HTMX requests:
def my_view(request):
context = {...}
if request.headers.get("HX-Request"):
return render(request, "app/_partial.html", context)
return render(request, "app/full_page.html", context)
Key points:
def create_view(request):
if request.method == "POST":
form = MyForm(request.POST)
if form.is_valid():
obj = form.save()
if request.headers.get("HX-Request"):
return render(request, "app/_item.html", {"item": obj})
return redirect("app:list")
# Return form with errors
if request.headers.get("HX-Request"):
return render(request, "app/_form.html", {"form": form})
else:
form = MyForm()
return render(request, "app/create.html", {"form": form})
HTMX respects special response headers for client-side behavior:
Trigger client-side events after response
response["HX-Trigger"] = "itemCreated"<div hx-get="/count/" hx-trigger="itemCreated from:body">Client-side redirect
response["HX-Redirect"] = reverse("app:detail", args=[obj.pk])Override hx-target and hx-swap from server
response["HX-Retarget"] = "#main"Force full page refresh
response["HX-Refresh"] = "true"hx-indicator - users click multiple times without feedback_partial.html, not full pages with base.html - check HX-Request headerhx-disabled-elt="this" to prevent duplicate submissionsselect_related()/prefetch_related() just like regular viewsshow_urls to verify HTMX endpointsAdapted from claude-code-django (.claude/skills/htmx-patterns).
development
pytest-django testing patterns, Factory Boy, fixtures, and TDD workflow. Use when writing tests, creating test factories, or following TDD red-green-refactor cycle.
development
Create distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
development
Check if documentation is in sync with code. Use when the user wants to verify that documentation matches current code, find outdated docs, or audit documentation accuracy. Triggers on requests like "check docs", "sync documentation", "are the docs up to date", "/docs-sync".
development
Django template patterns including inheritance, partials, tags, and filters. Use when working with templates, creating reusable components, or organizing template structure.