[Answered ]-Django custom tags with template blocks?

2👍

You need to use django inclusion tags

Infact, django admin itself uses these tags for very similar purpose.

From the documentation, Define a function like this, which is aware of the template it needs to render from

@register.inclusion_tag('results.html')
def show_results(poll):
    choices = poll.choice_set.all()
    return {'choices': choices}

And the template:

<ul>
{% for choice in choices %}
    <li> {{ choice }} </li>
{% endfor %}
</ul>

Then you insert a tag as follows:

{% show_results poll %}

Which will provide:

<ul>
   <li>First choice</li>
   <li>Second choice</li>
   <li>Third choice</li>
</ul>
👤lprsd

Leave a comment