django-cotton
Enabling Modern UI Composition in Django.
What it is and what it does
Django Cotton extends Django's template language to support component-based UI design. Instead of writing template fragments scattered across files, you define reusable components in a templates/cotton folder and invoke them with HTML-like syntax (<c-my-component />). Components support slots for content injection, named slots for multi-region layouts, attributes both static and dynamic, boolean flags, and Python data types. The package compiles components to native Django template tags at load time with built-in caching and automatic invalidation on file changes.
It solves the friction of composing modular UIs in Django without requiring a separate templating engine. Components encapsulate layout, styling, and interaction logic in one file, work well alongside Tailwind and Alpine.js, and integrate with HTMX for dynamic behavior. The syntax is HTML-native, so code editors provide highlighting, formatting, and autoclosing out of the box.
Use it for:
- Build a reusable button component with icon slots and URL attributes to avoid duplicating button markup across templates.
- Create form input components that accept arbitrary HTML attributes via the {{ attrs }} variable to reduce boilerplate.
- Compose a bio-card component that accepts context variables (:user="user") to render profiles without template duplication.
- Define HTMX-enabled components that can be rendered directly from views and reused across multiple pages.
- Organize complex layouts by nesting components with named slots to separate concerns between parent and child templates.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Django Cotton adds component-based UI composition to Django templates, letting you define reusable HTML components with slots, attributes, and template expressions without leaving Django's native template system.
Yes. Django Cotton is actively maintained, has no known vulnerabilities, installs with minimal friction, and solves a real pain point in Django template composition. It's marked Production/Stable and sits in the top 15000 packages by download volume. Install it if you want component-based UI design without leaving Django's template system.
Install
django-cotton on PyPI
pip
pip install django-cottonuv
uv add django-cottonpoetry
poetry add django-cottonInstalling django-cotton
Before you install
Low friction install as a pure Python wheel with only django as a runtime dependency. Marked as Production/Stable with active maintenance; last release 74 days ago.
License in practice
MIT license permits unrestricted use, modification, and distribution in both open-source and commercial projects with minimal obligations.
Quickstart
pip install django-cotton
# In settings.py
INSTALLED_APPS = [
'django_cotton'
]
# In templates/cotton/button.html
{{ slot }}
# In your template
<c-button url="/contact">Contact</c-button>
Verify before relying
- Whether the package works with all listed Python versions (3.8–3.14) in practice or if some are aspirational
- Performance impact of component compilation and caching on template rendering at scale
- Compatibility with Django versions beyond the classifier hints
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (<4,>=3.8) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — django |
| Maintenance | actively maintained — 74 days since the last release |
| First released | |
| Downloads | 419,317/month — #6,800 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: django_cotton-2.7.2-py3-none-any.whl
Keywords: django, components, ui
Tags
More Dynamic Content packages
MarkupSafe provides a text object that escapes…
permissive · top 100 on PyPI
Jinja2Jinja2 is a templating engine that renders…
permissive · top 100 on PyPI
soupsieveSoupsieve is a CSS selector library designed to…
permissive · top 100 on PyPI
WerkzeugWerkzeug is a WSGI utility library providing…
permissive · top 1,000 on PyPI
FlaskFlask is a lightweight WSGI web application…
permissive · top 1,000 on PyPI
MakoMako compiles Python-embedded templates into…
permissive · top 1,000 on PyPI
django-componentsdjango-components lets you build reusable,…
permissive · top 15,000 on PyPI
lacesLaces provides Django components that bundle…
permissive · top 5,000 on PyPI
ipyvuetifyProvides Jupyter notebook widgets built on…
permissive · top 15,000 on PyPI
django-admin-extra-buttonsAdds custom buttons, links, and views to Django…
permissive · top 15,000 on PyPI
trame-vuetifyProvides Material Design UI components…
permissive · top 5,000 on PyPI
reflex-components-codeProvides reusable code display components for…
permissive · top 15,000 on PyPI
django-bracesProvides reusable mixin classes for Django…
permissive · top 15,000 on PyPI
django-jinjaIntegrates Jinja2 templating into Django,…
permissive · top 15,000 on PyPI
django-template-partialsProvides reusable named template partials for…
permissive · top 15,000 on PyPI
django-htmxProvides Django integration utilities for htmx,…
permissive · top 5,000 on PyPI