Django templates: 'include' context

September 9, 2018

Something I learned today which should come handy. The include tag allows rendering a partial template from another:

{% include 'foo/bar.html' %}

So I was doing this to pass context to the included partial:

{% with obj=release %}
    {% include 'releases_widget.html' %}
{% endwith %}

And this why it’s good to read the docs, because apparently this can be done much better like so:

{% include 'releases_widget.html' with obj=release %}