[Django]-Components in Django

4👍

The closest to CMS’s components functionality in Django is Inclusion tags

👤UpVs

2👍

In 2021, I have come across the following projects:

I have used django-render-partial pretty extensively, and I like that the interface allows your partials to be used in templates, or hooked directly up to a urls.py.

django-components looks pretty cool, because it allows you to package CSS and JS files with the use of a Media class (similarly to Django forms), but it fractures the "everything is a view" pattern provided by django-render-partial.

1👍

I used django_components which saved me a lot of pain, it supports creating reusable components with dynamic components name, and it also allows passing HTML fragments to the components.

0👍

It was useful for me to learn about django-simple-components.

Here small example:

# file: templates/myapp/latest_news.html

{% load simple_components %}

{% set_component "article" %}
    <div class="card">
        <img src="{{ image }}" />
        <h3>{{ title }}</h3>
        <p>{{ description }}</p>
    </div>
{% end_set_component %}

<div class="news-list">
    {% component "article"
        image="https://..."
        title="Some lines"
        description="Other text..."
    %}

    {% component "article" image="https://..." title="Second Post" description="Second description..." %}
</div>
👤paqstd

Leave a comment