Django Misplaced Extends
ID |
python.django_misplaced_extends |
Severity |
low |
Remediation Complexity |
trivial |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Reliability |
Language |
Python |
Tags |
framework-django, reliability, template |
Description
Reports a {% extends %} tag that is not the first Django statement tag in the template. Django template inheritance requires {% extends %} to be the very first tag. Anything declared before it ({% load %}, {% comment %}, etc.) is silently ignored at render time — the writer’s {% load i18n %} does nothing, and {% trans "…" %} then fails with a confusing "Invalid block tag" error.
{% load i18n %}
{% extends "base.html" %} <!-- FLAW: extends must be first -->
{% extends "base.html" %} <!-- OK -->
{% load i18n %}
Rationale
Misplaced {% extends %} is a silent-failure bug — the file renders, the override appears to take effect, but the parent’s matching block is never substituted. Catching it at scan time is much cheaper than diagnosing missing content at runtime.