[Django]-Passing context from child to parent template in Django

0👍

Create a new block for books in child.html. This bookblock on child.html should override the bookblock exists inside base.html

{% bookblock %}
{% for book in books %}
    <ul>
        <li>{{ book.title }}</li>
        <li>{{ book.year_published }}</li>
    </ul>
{% endfor %} 
{% endblock %}

base.html

Put the code related to book inside a block where block name must be same on both base and child templates.

{% bookblock %}
{% for book in books %}
    <ul>
        <li>{{ book.title }}</li>
        <li>{{ book.year_published }}</li>
    </ul>
{% endfor %} 
{% endblock %}

Leave a comment