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
Thanks for writing and sharing this library, it's pretty handy! 👍 🌮
I've bumped into an issue when using a dynamic include like {% include variable_pointing_to_a_template_path %} -- which is supported by Django, but fails with TemplateDoesNotExist when you run get_node_instances(...) on a template that contains that (see example project attached).
I believe it would be a better behavior to skip loading the template in these cases (when it's a dynamic variable instead of a hardcoded path).
This is the Traceback:
>>> from django.template.loader import get_template
>>> from django.template.base import VariableNode
>>> from template_analyzer.djangoanalyzer import get_node_instances
>>> tmpl = get_template('index.html')
>>> get_node_instances(tmpl, VariableNode)
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/home/elias/.virtualenvs/web/local/lib/python2.7/site-packages/template_analyzer/djangoanalyzer.py", line 243, in get_node_instances
return _scan_nodes(nodelist, context, instances)
File "/home/elias/.virtualenvs/web/local/lib/python2.7/site-packages/template_analyzer/djangoanalyzer.py", line 158, in _scan_nodes
results += _extend_nodelist(node, context, instance_types)
File "/home/elias/.virtualenvs/web/local/lib/python2.7/site-packages/template_analyzer/djangoanalyzer.py", line 114, in _extend_nodelist
results += _scan_nodes(block.nodelist, context, instance_types, block, ignore_blocks=all_block_names)
File "/home/elias/.virtualenvs/web/local/lib/python2.7/site-packages/template_analyzer/djangoanalyzer.py", line 182, in _scan_nodes
results += _scan_nodes(subnodelist, context, instance_types, current_block)
File "/home/elias/.virtualenvs/web/local/lib/python2.7/site-packages/template_analyzer/djangoanalyzer.py", line 147, in _scan_nodes
template = get_template(node.template.var)
File "/home/elias/.virtualenvs/web/local/lib/python2.7/site-packages/django/template/loader.py", line 25, in get_template
raise TemplateDoesNotExist(template_name, chain=chain)
TemplateDoesNotExist: template_point
Here is the content of the main templates showing the issue (attached a full project reproducing it):
$ cat myapp/templates/index.html
{% extends "base.html" %}
{% block body %}
<h1>block index</h1>
{% with template_point="t1.html" %}
{% include template_point %}
{% endwith %}
{% endblock %}
$ cat myapp/templates/other.html
{% extends "base.html" %}
{% block body %}
<h1>block other</h1>
{% with template_point="t2.html" %}
{% include template_point %}
{% endwith %}
{% endblock %}
Hello!
Thanks for writing and sharing this library, it's pretty handy! 👍 🌮
I've bumped into an issue when using a dynamic include like
{% include variable_pointing_to_a_template_path %}
-- which is supported by Django, but fails withTemplateDoesNotExist
when you runget_node_instances(...)
on a template that contains that (see example project attached).I believe it would be a better behavior to skip loading the template in these cases (when it's a dynamic variable instead of a hardcoded path).
This is the Traceback:
Here is the content of the main templates showing the issue (attached a full project reproducing it):
testingproj.zip
The text was updated successfully, but these errors were encountered: