skillfed

django-cotton

Enabling Modern UI Composition in Django.

django-cotton v2.7.2 419.3K downloads/30d#6,800 on PyPI
Permissive license MIT Active released

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-cotton

uv

uv add django-cotton

poetry

poetry add django-cotton

Installing 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

Development Status :: 5 - Production/StableFramework :: DjangoIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9

Tags

django template componentsreusable ui components djangocomponent-based templatesdjango template compositionhtml-like component syntaxdjango slot systemmodular template design
django-templatesui-componentstemplate-composition

More Dynamic Content packages