--- id: django-cotton version: "2.7.2" license: MIT license_treatment: permissive maintenance: active --- # django-cotton — Enabling Modern UI Composition in Django. License: permissive · Maintenance: active · Downloads: 419.3K/mo ## 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 (). 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 above — 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 pip install django-cotton uv add django-cotton 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 Contact 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_current - Install friction: low - Maintenance: active - Downloads: 419.3K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags django template components, reusable ui components django, component-based templates, django template composition, html-like component syntax, django slot system, modular template design, django-templates, ui-components, template-composition [View on SkillFed](https://skillfed.io/packages/django-cotton) · [View on PyPI](https://pypi.org/project/django-cotton/)