django-overextends icon indicating copy to clipboard operation
django-overextends copied to clipboard

TemplateDoesNotExist in complex cases

Open nailgun opened this issue 8 years ago • 0 comments

I have found the issue in some complex cases when "extended-overriden" template contains "extended-overriden" includes. For example this template set causes TemplateDoesNotExist exception when looking for entry.txt template (while rendering index.txt):

project/app/templates/base.txt:

{% block header %}
Header.
{% endblock %}

{% block content %}
{% endblock %}

project/app/templates/index.txt:

{% extends 'base.txt' %}

{% block content %}
    {% for i in '123' %}
        {{ i }}
        {% include 'entry.txt' %}
    {% endfor %}
{% endblock %}

project/app/templates/entry.txt:

{% block name %}Entry{% endblock %} #{{ i }}

project/templates/entry.txt:

{% overextends 'base.txt' %}

{% block header %}MyEntry{% endblock %}

project/templates/entry.txt:

{% overextends 'entry.txt' %}

{% block name %}MyEntry{% endblock %}

Sometimes (depending on settings I suppose) instead of throwing an exception it renders but without "MyEntry" in third time.

If you change 123 to 12 in the loop, rendering will be successful. I don't know exactly why it fails at third iteration and not on second, but I have found a fix for this. Also it should address many other cases when such a glitch can happen. I will add a PR for this.

nailgun avatar May 20 '16 13:05 nailgun