September 9, 2018

Django templates: 'include' context

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 %}

Previous post
Restoring a database from Heroku for local development I’ve recently had to download my Django app’s database for local inspection. Heroku lets you do that pretty easily with: This gets you a file. Not
Next post
Django: Keeping logic out of templates (and views) When I first started dabbling with Django and web-development, a good friend with a little more experience advised that I should keep