@@ -324,7 +324,7 @@ def _resolve_includes_blocks_and_extends(template: str):
324
324
325
325
if endblock_match is None :
326
326
raise TemplateSyntaxError (
327
- "Missing {% endblock %}" ,
327
+ "No matching {% endblock %}" ,
328
328
Token (
329
329
template ,
330
330
offset + block_match .start (),
@@ -554,7 +554,7 @@ def _create_template_rendering_function( # pylint: disable=,too-many-locals,too
554
554
nested_if_statements .append (token )
555
555
elif token .content .startswith (r"{% elif " ):
556
556
if not nested_if_statements :
557
- raise TemplateSyntaxError ("Missing {% if ... %}" , token )
557
+ raise TemplateSyntaxError ("No matching {% if ... %}" , token )
558
558
559
559
indentation_level -= 1
560
560
function_string += (
@@ -563,14 +563,14 @@ def _create_template_rendering_function( # pylint: disable=,too-many-locals,too
563
563
indentation_level += 1
564
564
elif token .content == r"{% else %}" :
565
565
if not nested_if_statements :
566
- raise TemplateSyntaxError ("Missing {% if ... %}" , token )
566
+ raise TemplateSyntaxError ("No matching {% if ... %}" , token )
567
567
568
568
indentation_level -= 1
569
569
function_string += indent * indentation_level + "else:\n "
570
570
indentation_level += 1
571
571
elif token .content == r"{% endif %}" :
572
572
if not nested_if_statements :
573
- raise TemplateSyntaxError ("Missing {% if ... %}" , token )
573
+ raise TemplateSyntaxError ("No matching {% if ... %}" , token )
574
574
575
575
indentation_level -= 1
576
576
nested_if_statements .pop ()
@@ -585,7 +585,7 @@ def _create_template_rendering_function( # pylint: disable=,too-many-locals,too
585
585
nested_for_loops .append (token )
586
586
elif token .content == r"{% empty %}" :
587
587
if not nested_for_loops :
588
- raise TemplateSyntaxError ("Missing {% for ... %}" , token )
588
+ raise TemplateSyntaxError ("No matching {% for ... %}" , token )
589
589
590
590
indentation_level -= 1
591
591
last_forloop_iterable = (
@@ -597,7 +597,7 @@ def _create_template_rendering_function( # pylint: disable=,too-many-locals,too
597
597
indentation_level += 1
598
598
elif token .content == r"{% endfor %}" :
599
599
if not nested_for_loops :
600
- raise TemplateSyntaxError ("Missing {% for ... %}" , token )
600
+ raise TemplateSyntaxError ("No matching {% for ... %}" , token )
601
601
602
602
indentation_level -= 1
603
603
nested_for_loops .pop ()
@@ -612,7 +612,7 @@ def _create_template_rendering_function( # pylint: disable=,too-many-locals,too
612
612
nested_while_loops .append (token )
613
613
elif token .content == r"{% endwhile %}" :
614
614
if not nested_while_loops :
615
- raise TemplateSyntaxError ("Missing {% while ... %}" , token )
615
+ raise TemplateSyntaxError ("No matching {% while ... %}" , token )
616
616
617
617
indentation_level -= 1
618
618
nested_while_loops .pop ()
@@ -622,7 +622,7 @@ def _create_template_rendering_function( # pylint: disable=,too-many-locals,too
622
622
expression = token .content [8 :- 3 ]
623
623
function_string += indent * indentation_level + f"{ expression } \n "
624
624
625
- # Token is autoescape mode change
625
+ # Token is a autoescape mode change
626
626
elif token .content .startswith (r"{% autoescape " ):
627
627
mode = token .content [14 :- 3 ]
628
628
if mode not in ("on" , "off" ):
@@ -632,31 +632,31 @@ def _create_template_rendering_function( # pylint: disable=,too-many-locals,too
632
632
633
633
elif token .content == r"{% endautoescape %}" :
634
634
if not nested_autoescape_modes :
635
- raise TemplateSyntaxError ("Missing {% autoescape ... %}" , token )
635
+ raise TemplateSyntaxError ("No matching {% autoescape ... %}" , token )
636
636
637
637
nested_autoescape_modes .pop ()
638
638
639
639
else :
640
- raise TemplateSyntaxError (f"Unknown token type : { token .content } " , token )
640
+ raise TemplateSyntaxError (f"Unknown token: { token .content } " , token )
641
641
642
642
else :
643
- raise TemplateSyntaxError (f"Unknown token type : { token .content } " , token )
643
+ raise TemplateSyntaxError (f"Unknown token: { token .content } " , token )
644
644
645
645
# Move offset to the end of the token
646
646
offset += token_match .end ()
647
647
648
648
# Checking for unclosed blocks
649
649
if len (nested_if_statements ) > 0 :
650
650
last_if_statement = nested_if_statements [- 1 ]
651
- raise TemplateSyntaxError ("Missing {% endif %}" , last_if_statement )
651
+ raise TemplateSyntaxError ("No matching {% endif %}" , last_if_statement )
652
652
653
653
if len (nested_for_loops ) > 0 :
654
654
last_for_loop = nested_for_loops [- 1 ]
655
- raise TemplateSyntaxError ("Missing {% endfor %}" , last_for_loop )
655
+ raise TemplateSyntaxError ("No matching {% endfor %}" , last_for_loop )
656
656
657
657
if len (nested_while_loops ) > 0 :
658
658
last_while_loop = nested_while_loops [- 1 ]
659
- raise TemplateSyntaxError ("Missing {% endwhile %}" , last_while_loop )
659
+ raise TemplateSyntaxError ("No matching {% endwhile %}" , last_while_loop )
660
660
661
661
# No check for unclosed autoescape blocks, as they are optional and do not result in errors
662
662
0 commit comments