DEV Community

Przemysław Górecki
Przemysław Górecki

Posted on

Looking for a component-based Django template rendering library

One of the greatest features of React is the possibility of defining components - independent and reusable bits of HTML code. I really miss it in Django templates. I imagine this could work like so:

{% component Link %}
  <a href="{{href}}">{{children}}</a>
{% endcomponent %}

{% component Card %}
  <div class="card">
    {%if title}
      <div class="card-title">{{title}}</div>
    <div class="card-content">
{% endcomponent %}

{% usecomponents %}
  <Card title="Foo">
    I am a very simple card. I am good at containing small bits of information. I am convenient because I require little markup to use effectively.
    <Link href="#">Click Me</Link>
{% endusecomponents %}
Enter fullscreen mode Exit fullscreen mode

How do you like the idea? Are you aware of any libraries that solves this problem?

Top comments (1)

hanifbirgani profile image
Hanif Birgani

Have you seen django-components package?