The smallest useful fragment endpoint proves the whole pipeline: a button, an HTMX attribute, and a Django view that returns the server time as an HTML fragment.
The endpoint
/fragment/ping/ renders the current timestamp into a small div. A request with the HX-Request header swaps it into the page — no JSON, no re-render of the document, no client state.
from django.http import HttpResponse
from django.utils import timezone
def server_time(request):
now = timezone.now().isoformat()
if request.headers.get('HX-Request'):
return HttpResponse(f'{now}')
return HttpResponse(f'Server time: {now}
')
Why it matters
If a five-line fragment endpoint works end to end, the heavier regions — contact forms, newsletter signup, product filters — ride the same rails. The demo is trivial; the architecture it proves is not.
Comments
Sign in to join the conversation.
Commenting as