[Fixed]-Django include – using the correct include depending on the page

1👍

Create a block in your base template, something like {% block sidebar %}{% endblock %}

Then in your home page template do

{% extends 'your-base-template-name-here' %}

{% block sidebar %}
     {% include "modules/include/sidebar.html" %}
{% endblock %}

And in your article template use

{% extends 'your-base-template-name-here' %}

{% block sidebar %}
     {% include "modules/include/article-sidebar.html" %}
{% endblock %}

More about template inheritance here https://docs.djangoproject.com/en/1.9/ref/templates/language/#id1

Leave a comment