Closed joshuadavidthomas closed 9 months ago
ChatGPT suggested the fact that we were setting self.nav
back to the resolved template variable is the cause. Implementing it's fix seems to have fixed the issue:
# django_template_nav/templatetags/django_template_nav.py
...
class DjangoSimpleNavNode(template.Node):
...
def render(self, context):
try:
resolved_nav = self.nav.resolve(context)
resolved_template_name = (
self.template_name.resolve(context) if self.template_name else None
)
except template.VariableDoesNotExist as err:
raise template.TemplateSyntaxError(
f"Variable does not exist: {err}"
) from err
if isinstance(resolved_nav, str):
try:
nav = import_string(resolved_nav)()
except ImportError as err:
raise template.TemplateSyntaxError(
f"Failed to import: {resolved_nav}"
) from err
else:
nav = resolved_nav
if not hasattr(nav, "render"):
raise template.TemplateSyntaxError(
"The object does not have a 'render' method."
)
return nav.render(context["request"], resolved_template_name)
In clicking around on the demo in #42, this error sometimes pops up. It's random and inconsistent.