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.
.cursor/rules/htmx-django-cursorrules-prompt-file.mdcWhat 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
staticfilesinstead 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.mdcFrontmatter: description, globs, alwaysApply
Manually: put the files in place
.claude/rules/htmx-django-cursorrules-prompt-file.mdThe paths frontmatter field limits the files: move globs from the source into paths
AGENTS.md
Codex reads AGENTS.md: paste the rule text there
Manually: put the files in place
.github/instructions/htmx-django-cursorrules-prompt-file.instructions.mdThe applyTo field sets which files it applies to: move globs from the source into applyTo
Manually: put the files in place
.devin/rules/htmx-django-cursorrules-prompt-file.mdManually: put the files in place
.clinerules/htmx-django-cursorrules-prompt-file.mdStep 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