Skip to main content

django-component

Modern components for django templates Declarative and composable components inspired by javascript frameworks.

Supports Python 3.6+ and Django 1.11, 2.0+, and 3.0+

Usage

Describe your component:

# myapp/templatetags/mycomponents.py

from django_component import Library, Component

register = Library()

@register.component
class Card(Component):
    template = "myapp/card.html"

    class Media:
        css = {"all": ["myapp/card.css"]}
        js = ["myapp/card.js"]
# myapp/templates/myapp/card.html

<section class="card">
    <header>{{ header }}</header>
    <h1>{{ short_title }}</h1>
    <div>{{ children }}</div>
</section>

And use them in your templates

{% load mycomponents %}
{% components_css %}

{% Card title="My card's title" %}
    This will be accessible as the `children` variable.
    It's just django template, <span>{{ variable }}</span> !

    {% arg header %}
        This <img src="foo.jpg" />
        will be in the header of the card
    {% endarg %}
{% /Card %}

{% components_js %}

django-component also enable context processing per component, see the documentation (TODO) for the complete api.

Why django-component?

django-component make it easy to create reusable template components. Django has some features to address this, but they all come with some limitations. django-component unify these features (block, includes, inclusion_tag, simple_tag) under an unique api. In addition django-component address one of my greatest frustration with reusable components in django: tracking css and js dependencies for each component and include them only when they are effectively used.

Installation

pip install django-component

Then add django-component to your INSTALLED_APPS, it is also recommended to add django-component.templatetags as builtins templatetags

INSTALLED_APPS = [
    ...,
    "django_component",
    ...
]


TEMPLATES=[
    {
        'OPTIONS': {
            'builtins': [
                'django_component.templatetags',
            ]
        },
    }
],

Release files for django-component 0.1.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-component 0.1.7
File Size Uploaded
django-component-0.1.7.tar.gz 7.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-component 0.1.7
File Interpreter ABI Platform
django_component-0.1.7-py3-none-any.whl Python 3 none any Details

Total release size: 16.0 kB

Release files / django-component-0.1.7.tar.gz

Download URL django-component-0.1.7.tar.gz
Size 7.5 kB
Tags Source
SHA-256 checksum
How to use checksums
bd414f2d44a7211d1a4d95a4a31c1dff9f6ada4450092afd95039a0c900cbbb4
BLAKE2b-256 checksum
How to use checksums
80e5fcdc6147e599ee5777d3490282239316d5c372a2585381632e598a70f97c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.0.10 CPython/3.8.5 Linux/5.8.6-arch1-1

Release files / django_component-0.1.7-py3-none-any.whl

Download URL django_component-0.1.7-py3-none-any.whl
Size 8.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c90a437cac226edc433e6378b77bd9b7fa446b0cc0157a558f792a38347879a7
BLAKE2b-256 checksum
How to use checksums
64cf444e690a9edac7b21f3f71925ac2a6ea2182c1734d15a3548dc8952651e6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.0.10 CPython/3.8.5 Linux/5.8.6-arch1-1

Release history Release notifications | RSS feed

This release

0.1.7 This release

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page