Django Endblock Mismatch

ID

python.django_endblock_mismatch

Severity

low

Remediation Complexity

trivial

Remediation Risk

low

Remediation Effort

low

Resource

Reliability

Language

Python

Tags

framework-django, reliability, template

Description

Reports an {% endblock NAME %} whose name does not match the most recent open {% block NAME %}. Django allows the trailing name on endblock as a readability aid; if it disagrees with the opener Django raises TemplateSyntaxError: Mismatched endblock for X.

{% block header %}
  ...
{% endblock footer %}      <!-- FLAW: header / footer mismatch -->

{% block header %}
  ...
{% endblock %}              <!-- OK — bare endblock -->

{% block header %}
  ...
{% endblock header %}      <!-- OK -->

Rationale

The trailing name on {% endblock %} is a readability aid, not a structural requirement. When it disagrees with the opener, the writer either renamed one half during a refactor or pasted the closer from an unrelated block — either way, render fails with a confusing message at the wrong line.

Remediation

Either drop the name on {% endblock %} or correct it to match the opener.

References