DEV Community

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

Posted on

4 2

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>
    {%endif}
    <div class="card-content">
      {{children}}
    </div>
  </div>
{% endcomponent %}

{% usecomponents %}
<body>
  <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>
  </Card>
</body>
{% 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)

Collapse
 
hanifbirgani profile image
Hanif Birgani

Have you seen django-components package?
github.com/EmilStenstrom/django-co...

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay