django-templates
Skill177 starsChanged 10 months agoMITView on GitHub
Django template patterns including inheritance, partials, tags, and filters. Use when working with templates, creating reusable components, or organizing template structure.
We split this skill into the rules it gives an agent
4 rules. About 0 are common, 1 is distinctive, and 3 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 30
Use three-level inheritance for consistent layouts:
- Very specific: line 51
Add only to isolate context: {% include "_card.html" with title=post.title only %}
- Very specific: line 69
Use user.can_moderate not user.role == "admin" or user.role == "moderator"
- Very specific: line 78
Always include {% empty %} clause in loops that might have no items
≈ “Common” is an estimate: at least 1 in 5 of the 308,232 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Django Template Patterns
Template Organization
templates/
├── base.html # Root template with common structure
├── partials/ # Reusable fragments (navbar, footer, pagination)
├── components/ # UI components (button, card, modal)
└── <app>/ # App-specific templates
├── list.html # Full pages extend base.html
├── detail.html
├── _list.html # HTMX partials (underscore prefix)
└── _form.htmlNaming conventions:
- Full pages:
list.html,detail.html,form.html - HTMX partials:
_list.html,_card.html(underscore prefix) - Shared partials:
partials/_navbar.html,partials/_pagination.html - Components:
components/_button.html,components/_modal.html
Template Inheritance
Use three-level inheritance for consistent layouts:
- base.html - Site-wide structure (HTML skeleton, navbar, footer)
- Section templates - Optional intermediate templates for sections with shared elements
- Page templates - Individual pages that extend base or section templates
Standard blocks to define in base.html:
title- Page title (use{{ block.super }}to append to site name)content- Main page contentextra_css- Page-specific stylesheetsextra_js- Page-specific scripts
Partials and Components
Partials are template fragments included in other templates. Use for:
- Repeated content (pagination, empty states)
- HTMX responses that replace portions of the page
- Keeping templates DRY
Components are self-contained UI elements with configurable behavior. Pass context with:
{% include "components/_button.html" with text="Submit" variant="primary" %}- Add
onlyto isolate context:{% include "_card.html" with title=post.title only %}
Custom Tags and Filters
When to create custom template tags:
simple_tag- Return a string value (e.g., active link class, formatted output)inclusion_tag- Render a template fragment (e.g., pagination component, user avatar)
When to create custom filters:
- Transform a single value (e.g., initials from name, percentage calculation)
- Chain with other filters for composable transformations
Location: apps/<app>/templatetags/<app>_tags.py (create __init__.py in templatetags directory)
Anti-Patterns
Move logic out of templates:
- Complex conditionals belong in views or model methods
- Use
user.can_moderatenotuser.role == "admin" or user.role == "moderator"
Use URL names, not hardcoded paths:
- Use
{% url 'posts:detail' pk=post.pk %}not/posts/{{ post.id }}/
Use CSS classes, not inline styles:
- Use
class="error-message"notstyle="color: red;"
Handle empty states:
- Always include
{% empty %}clause in loops that might have no items
Integration with Other Skills
- htmx-patterns - HTMX partial templates and dynamic UI
- django-forms - Form rendering and validation patterns
- pytest-django-patterns - Testing template rendering
In this repository16 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- celery-patternsSkill
- code-qualitySkill
- django-extensionsSkill
- django-formsSkill
- django-modelsSkill
- docs-syncSkill
- htmx-patternsSkill
- onboardSkill
- pr-reviewSkill
- pr-summarySkill
- pytest-django-patternsSkill
- skill-creatorSkill
- systematic-debuggingSkill
- ticketSkill
- worktree-commit-mergeSkill
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
Reviews can't be read right now.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

