Looking for a component-based Django template rendering library

pgorecki

Przemysław Górecki

Posted on April 1, 2021

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?

💖 💪 🙅 🚩
pgorecki
Przemysław Górecki

Posted on April 1, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Choosing the Right Relational Database
undefined Choosing the Right Relational Database

November 29, 2024

Can a Solo Developer Build a SaaS App?
undefined Can a Solo Developer Build a SaaS App?

November 29, 2024

This Week In Python
python This Week In Python

November 29, 2024