'str' object has no attribute 'render_annotated' Error when using a for loop to iterate objects

All i am doing is just iterating through a queryset that i passed into the template using context in views.
It was working with django version 3.1.2 but after i upgraded to django 5 i get the mentioned error

<div class="list-group">
                {% for i in b%}
                <a href="{% url 'whatever:whatever' i %}" class="list-group-item list-group-item-action">{{i}}</a>
                {%endfor%}
              </div> ```

Found the issue after 2 days. There seems to be some kind of bug regarding the multiforloop package i had installed

After looking at it further:

reverting this change:

class NodeList(list):
    # Set to True the first time a non-TextNode is inserted by
    # extend_nodelist().
    contains_nontext = False

    def render(self, context):
        return SafeString("".join([node.render_annotated(context) for node in self]))

to this:

class NodeList(list):
    # Set to True the first time a non-TextNode is inserted by
    # extend_nodelist().
    contains_nontext = False

    def render(self, context):
        bits = []
        for node in self:
            if isinstance(node, Node):
                bit = node.render_annotated(context)
            else:
                bit = node
            bits.append(str(bit))
        return mark_safe(''.join(bits))

fixes the issue while still making multiforloop usable. Dont know if it is safe tho

UPDATE
this also works:

class NodeList(list):
    # Set to True the first time a non-TextNode is inserted by
    # extend_nodelist().
    contains_nontext = False

    def render(self, context):
        return SafeString("".join([node.render_annotated(context) if isinstance(node,Node) else node for node in self]))
1 Like