Skip to main content
rule

htmx-django-cursorrules-prompt-file — Cursor rule: HTMX with Django

A Cursor rule that keeps the agent on Django rails while it writes HTMX code: templates, forms, CSRF, class-based views.

Install into Cursor · Manually: put the files in place All methods and platforms ↓
.cursor/rules/htmx-django-cursorrules-prompt-file.mdc
Open on GitHub

What htmx-django-cursorrules-prompt-file does

The rule spells out how the agent should write code where HTMX meets Django. First block is a practice list: use Django's template system with HTMX attributes, handle forms through Django forms, lean on the built-in URL routing, and use class-based views for HTMX responses. The agent also keeps the ORM and middleware in mind for request and response handling.

Second block pins down folder layout. Templates and static files live inside the app, next to models.py, views.py and urls.py; settings and the root urls.py sit in the project package beside manage.py. Then come seven instructions: template tags with HTMX attributes, CSRF protection through Django's own features, HttpResponse for HTMX-specific responses, form validation, error handling and logging, and static assets via the staticfiles app.

The rule ships with alwaysApply: false and the **/* glob, so it does not switch itself on — you enable it by hand or attach it to the files you care about. Nothing here applies to FastAPI or Flask work; the whole text is Django. Install is one file at .cursor/rules/htmx-django-cursorrules-prompt-file.mdc.

What it helps with

  • get the agent to return partial responses to HTMX requests through Django
  • keep the CSRF token in forms that HTMX submits
  • hold one Django project layout steady while code is generated
  • wire Django form validation into HTMX responses
  • serve static assets through staticfiles instead of by hand

Example prompts for the agent

  • Add a Django view that returns only a template fragment for an HTMX request
  • Build a Django form with CSRF that submits over HTMX
  • Lay out the new app the way the rule says: templates, static, models.py, views.py, urls.py

How to install htmx-django-cursorrules-prompt-file

Manually: put the files in place

.cursor/rules/htmx-django-cursorrules-prompt-file.mdc

Frontmatter: description, globs, alwaysApply

Step by step, with commands for each platform: Cursor rules: .mdc files, four modes and what replaced .cursorrules

Questions about htmx-django-cursorrules-prompt-file

How do I install htmx-django-cursorrules-prompt-file in Cursor?

Drop the file at .cursor/rules/htmx-django-cursorrules-prompt-file.mdc in your project root. Cursor picks up rules from that folder.

What does htmx-django-cursorrules-prompt-file do?

It gives the agent a set of practices for HTMX code inside Django: templates, forms, URL routing, class-based views, the ORM, middleware. It also fixes the project folder structure and adds seven instructions covering CSRF, validation, logging and static files.

Does the rule apply to every file on its own?

No. It carries alwaysApply: false, so it stays off until you enable it or attach it to specific files. The **/* glob defines the scope it can cover.

Source text

htmx-django-cursorrules-prompt-file.mdc · CC0-1.0
---
description: "Cursor rules for HTMX development with Django integration."
globs: **/*
alwaysApply: false
---
// HTMX with Django .cursorrules

// HTMX and Django best practices

const htmxDjangoBestPractices = [
  "Use Django's template system with HTMX attributes",
  "Implement Django forms for form handling",
  "Utilize Django's URL routing system",
  "Use Django's class-based views for HTMX responses",
  "Implement Django ORM for database operations",
  "Utilize Django's middleware for request/response processing",
];

// Folder structure

const folderStructure = `
project_name/
  app_name/
    templates/
    static/
      css/
      js/
    models.py
    views.py
    urls.py
  project_name/
    settings.py
    urls.py
manage.py
`;

// Additional instructions

const additionalInstructions = `
1. Use Django's template tags with HTMX attributes
2. Implement proper CSRF protection with Django's built-in features
3. Utilize Django's HttpResponse for HTMX-specific responses
4. Use Django's form validation for HTMX requests
5. Implement proper error handling and logging
6. Follow Django's best practices for project structure
7. Use Django's staticfiles app for managing static assets
`;

© PatrickJS · CC0-1.0 · PatrickJS/awesome-cursorrules

Similar IDE rules

All IDE rules for Backend and APIs →

From the same set68

kubernetes-mkdocs-documentation-cursorrules-prompt A Cursor rule that turns the agent into a technical writer for Kubernetes and cloud native docs built with Markdown and MkDocs. ★ 41,011repo stars knative-istio-typesense-gpu-cursorrules-prompt-fil A Cursor rule that turns the assistant into a helper for serverless projects built on Knative with Istio, Typesense and HTMX. Useful when your search app runs on that stack. ★ 41,011repo stars javascript-chrome-apis-cursorrules-prompt-file A Cursor rule that points the AI agent at Chrome extension work: manifest, architecture, Chrome API usage. ★ 41,011repo stars htmx-go-fiber-cursorrules-prompt-file A Cursor rule for Go projects built on Fiber with HTMX: it pins down folder layout, routing and template rendering so the agent stops improvising. ★ 41,011repo stars how-to-documentation-cursorrules-prompt-file A Cursor rule that turns technical steps, test scripts and screenshots into step-by-step guides for non-technical users. Useful when you write How To docs for a feature. ★ 41,011repo stars graphical-apps-development-cursorrules-prompt-file A Cursor rule that feeds the agent the Pyllments context: graph-based LLM apps in Python built on Panel and Langchain. ★ 41,011repo stars flutter-development-guidelines-cursorrules-prompt-file Locks down folder layout, naming and Dart style for Flutter apps built on MVVM with Riverpod. Useful when the agent scatters files across the project. ★ 41,011repo stars embedded-stm32-hal A Cursor rule that keeps the agent inside embedded C/C++ conventions: STM32 HAL, interrupts, DMA and tight memory budgets. ★ 41,011repo stars

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor