[Answer]-Show elements of m2m based on template in a template

1đź‘Ť

âś…

You can use the include templatetag for this.

Loads a template and renders it with the current context. This is a way of “including” other templates within a template

{% for author in book.authors.all %}

    {% include "author_short.html" %}

{% endfor %}

and author_short.html can still be:

<div style="border: 1px solid #f00;">
    Name: {{ first_name }} {{ last_name }} 
</div>

which can be reused

👤karthikr

Leave a comment