Opened 14 years ago
Closed 14 years ago
#14169 closed (wontfix)
Improve TemplateSyntaxError for invalid block tags
Reported by: | Filip Dupanović | Owned by: | nobody |
---|---|---|---|
Component: | Template system | Version: | dev |
Severity: | Keywords: | TemplateSyntaxError, exception value | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
some_template.html:
{% block someblock %}{% endblock %}
some_other_template.html:
{% extends 'some_template.html' %}
{% block someblock %}
{% blocktrans %}
Hello world!
{% endblocktrans%}
{% endlbock %}
Django raises a TemplateSyntaxError with an exception value "Invalid block tag: 'blocktrans', expected 'endblock' or 'endblock someblock'. Because I didn't take my morning coffee, this put me way off thinking since when was {% blocktrans %} an invalid node for {% block %}? 20 minutes later, after reverting from trunk to the v1.2 tag, I've just figured I've never loaded the {% blocktrans %} tag in the first place. Could this particular instance of TemplateSyntaxError be expanded to perform an additional check to see if sometag
is actually loaded.
This would seem a more appropriate exception value:
Invalid block tag: 'blocktrans'
Attachments (1)
Change History (3)
comment:1 by , 14 years ago
comment:2 by , 14 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
I don't really think it's feasible either
by , 12 years ago
Attachment: | Django Installation Guide added |
---|
This is hard to do, next to impossible even with the current code base.
In django.template.Parser.invalid_block_tag, we can determine which tags are allowed using self.tags. However, this dict only contains f.e. 'block', not 'endblock', only 'blocktrans', not 'endblocktrans'. We have no way of knowing whether 'endblock' or 'endblocktrans' are valid tags because the template tag author can freely choose tag names as he/she wants. It gets even worse with {% plural %} inside a blocktrans-block...
Here's my stupid attempt at a patch, if anyone wants to continue: