Hi !
There is a discussion for this topic on the Ticket tracker at #35790 (Deprecate content outside of {% block %} tags when {% extends %} is used) – Django !
The main concern behind this is that whenever we write some text in a template after the {% extends %}
which is not in some tag, just silently gets discarded , which could alter the output from what the user expected.
An example would be:-
{% extends 'egg.html' %}
<title>Chicken egg</title>
{% block yolk %}
yellow
{% endblock yolk %}
Here, the title Chicken egg is never displayed ! It is silently discarded.
This was solved earlier (not pushed to django main) by raising a deprecation warning whenever there is some text outside a tag after the {% extends %}
tag.
But there is an issue. As pointed by @TomHall2020 and @ChrisAdams , the warning will be raised even in scenarios where not intended. For clearance, see the comment.
In the case of html comment, like <!-- -->
or variable tag {{ some_var }}
, the warning is still raised which we don’t want !
Now, there are multiple ways to solve this and opinions are welcome !
- We neglect these cases and simply implement the deprecation warning (for 7.0) for any text outside a tag after {% extends %} tag , also for the {{}} variable node.
- We implement the deprecation warning for the text and variable node as before but also check for comment inside the text using regex for
<!-- -->
and only raise the warning if we encounter some text outside this (except newline) or a variable node (cause it won’t be displayed). This one could be an overkill so plz do suggest. - We implement the (1) but instead of the deprecation warning, it’s a simple warning in debug mode only.
- Just not do anything cause the problem seems easier than the solution and the solution is a bit too overkill.
Waiting for the reviews ! Btw github link :- Fixed #35790 - Added warning for non whitespace text outside {% extends %} tag by YogyaChugh · Pull Request #19302 · django/django · GitHub where more elaborated by @a-ludi