[Django]-Override inner template block in Django

2👍

I don’t think that you’re going to have any luck going about it that way. A simple solution could be to have an optional variable that base2.html looks at, which determines the alternate order. In fact it may even be that you can define the presence of this variable in the article.html template itself. I haven’t tried this, but something like the following may work:

{% with alternate_order=1 %}
    {% include base4.html
{% endwith %}

1👍

Why do you have so many levels of inheritance? As a note, django provides no limitations, but typically we use the three-level approach. See docs

Here are a few suggestions:

  • You can probably combine base1.html and base2.html.
  • If you can put the html code in the parent then do so. I usually implement my templates like this:
    • <div id='sidebar'>{% block sidebar_content %}{% endblock %}</div>

As for your problem, if you need a different layout, that’s when you branch. That is, if using a different css won’t work.

Leave a comment