mirror of https://github.com/django/django.git
Fixed #25423 -- Made error message for unknown template tag more helpful.
This commit is contained in:
parent
2875325889
commit
9f2881deb1
|
@ -553,13 +553,18 @@ class Parser(object):
|
|||
if parse_until:
|
||||
raise self.error(
|
||||
token,
|
||||
"Invalid block tag on line %d: '%s', expected %s" % (
|
||||
"Invalid block tag on line %d: '%s', expected %s. Did you "
|
||||
"forget to register or load this tag?" % (
|
||||
token.lineno,
|
||||
command,
|
||||
get_text_list(["'%s'" % p for p in parse_until]),
|
||||
),
|
||||
)
|
||||
raise self.error(token, "Invalid block tag on line %d: '%s'" % (token.lineno, command))
|
||||
raise self.error(
|
||||
token,
|
||||
"Invalid block tag on line %d: '%s'. Did you forget to register "
|
||||
"or load this tag?" % (token.lineno, command)
|
||||
)
|
||||
|
||||
def unclosed_block_tag(self, parse_until):
|
||||
command, token = self.command_stack.pop()
|
||||
|
|
|
@ -68,14 +68,21 @@ class TemplateTests(SimpleTestCase):
|
|||
#7876 -- Error messages should include the unexpected block name.
|
||||
"""
|
||||
engine = Engine()
|
||||
|
||||
with self.assertRaises(TemplateSyntaxError) as e:
|
||||
msg = (
|
||||
"Invalid block tag on line 1: 'endblock', expected 'elif', 'else' "
|
||||
"or 'endif'. Did you forget to register or load this tag?"
|
||||
)
|
||||
with self.assertRaisesMessage(TemplateSyntaxError, msg):
|
||||
engine.from_string("{% if 1 %}lala{% endblock %}{% endif %}")
|
||||
|
||||
self.assertEqual(
|
||||
e.exception.args[0],
|
||||
"Invalid block tag on line 1: 'endblock', expected 'elif', 'else' or 'endif'",
|
||||
def test_unknown_block_tag(self):
|
||||
engine = Engine()
|
||||
msg = (
|
||||
"Invalid block tag on line 1: 'foobar'. Did you forget to "
|
||||
"register or load this tag?"
|
||||
)
|
||||
with self.assertRaisesMessage(TemplateSyntaxError, msg):
|
||||
engine.from_string("lala{% foobar %}")
|
||||
|
||||
def test_compile_filter_expression_error(self):
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue