You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If I use the jinja2.FileSystemLoader and there is an error within my Jinja2 template then the Exception is raised and it reports the file that caused the issue, e.g:
File "test.j2", line 1, in template
Test {% x
jinja2.exceptions.TemplateSyntaxError: Encountered unknown tag 'x'.
However, if I use jinja2.DictLoader then when it raises an Exception it reports the file as <unknown> even though I am passing it the name of a template, e.g:
File "<unknown>", line 1, in template
jinja2.exceptions.TemplateSyntaxError: Encountered unknown tag 'x'.
Traceback (most recent call last):
File "/home/cmason3/./test.py", line 11, in <module>
rtemplate = env.get_template('Default')
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/cmason3/bin/python3/lib/python3.11/site-packages/jinja2/environment.py", line 1013, in get_template
return self._load_template(name, globals)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/cmason3/bin/python3/lib/python3.11/site-packages/jinja2/environment.py", line 972, in _load_template
template = self.loader.load(self, name, self.make_globals(globals))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/cmason3/bin/python3/lib/python3.11/site-packages/jinja2/loaders.py", line 138, in load
code = environment.compile(source, name, filename)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/cmason3/bin/python3/lib/python3.11/site-packages/jinja2/environment.py", line 768, in compile
self.handle_exception(source=source_hint)
File "/home/cmason3/bin/python3/lib/python3.11/site-packages/jinja2/environment.py", line 939, in handle_exception
raise rewrite_traceback_stack(source=source)
File "<unknown>", line 1, in template
jinja2.exceptions.TemplateSyntaxError: Encountered unknown tag 'Test'.
As we are passing the name of the template into get_template() then it knows the name of the template - the same is true if it includes another template from the dict - is it possible to actually report the template name (instead of <unknown> - maybe <actual template name>) when using the DictLoader? When I include multiple templates it gets quite confusing to understand which template the error occurred in - the line numbers seem to be correct once I work out what template it is referring to.
Environment:
Python version: 3.11.2
Jinja version: 3.1.4
The text was updated successfully, but these errors were encountered:
If I use the
jinja2.FileSystemLoader
and there is an error within my Jinja2 template then the Exception is raised and it reports the file that caused the issue, e.g:However, if I use
jinja2.DictLoader
then when it raises an Exception it reports the file as<unknown>
even though I am passing it the name of a template, e.g:The following code replicates the issue:
The full trackback is as follows:
As we are passing the name of the template into
get_template()
then it knows the name of the template - the same is true if it includes another template from the dict - is it possible to actually report the template name (instead of<unknown>
- maybe<actual template name>
) when using the DictLoader? When I include multiple templates it gets quite confusing to understand which template the error occurred in - the line numbers seem to be correct once I work out what template it is referring to.Environment:
The text was updated successfully, but these errors were encountered: