File tree 2 files changed +19
-1
lines changed
tests/template_tests/syntax_tests
2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -257,6 +257,13 @@ def construct_relative_path(
257
257
# relative path.
258
258
return relative_name
259
259
260
+ if current_template_name is None :
261
+ # Unknown origin (e.g. Template('...').render(Context({...})).
262
+ raise TemplateSyntaxError (
263
+ f"The relative path { relative_name } cannot be evaluated due to "
264
+ "an unknown template origin."
265
+ )
266
+
260
267
new_name = posixpath .normpath (
261
268
posixpath .join (
262
269
posixpath .dirname (current_template_name .lstrip ("/" )),
Original file line number Diff line number Diff line change 1
- from django .template import TemplateDoesNotExist , TemplateSyntaxError
1
+ from django .template import Template , TemplateDoesNotExist , TemplateSyntaxError
2
2
from django .test import SimpleTestCase
3
3
4
4
from ..utils import setup
@@ -64,3 +64,14 @@ def test_exception05(self):
64
64
"""
65
65
with self .assertRaises (TemplateSyntaxError ):
66
66
self .engine .render_to_string ("exception05" )
67
+
68
+ def test_unknown_origin_relative_path (self ):
69
+ files = ["./nonexistent.html" , "../nonexistent.html" ]
70
+ for template_name in files :
71
+ with self .subTest (template_name = template_name ):
72
+ msg = (
73
+ f"The relative path '{ template_name } ' cannot be evaluated due to "
74
+ "an unknown template origin."
75
+ )
76
+ with self .assertRaisesMessage (TemplateSyntaxError , msg ):
77
+ Template (f"{{% extends '{ template_name } ' %}}" )
You can’t perform that action at this time.
0 commit comments