<s>[INST] I have a use case where I need to iterate over a dictionary of values within a django template using a for loop, like so:

{% for key, value in dictionary.items %}
    {{ key }} : {{ value }}
{% endfor %}

However, the dictionary is defined inside a class and is an instance attribute of that class.

Something like this:

from django.template import Template
from django.template.loader import render_to_string

class MyClass:
    def __init__(self):
        self.my_dictionary = {'a': 1, 'b': 2, 'c': 3}

    def render_template(self):
        template_string = '<ul>{% for key, value in my_dictionary.items %}<li>{{ key }} : {{ value }}</li>{% endfor %}</ul>'
        template = Template(template_string)
        return template.render({'my_dictionary': self.my_dictionary, })

obj = MyClass()
print(obj.render_template())

But this will fail with a TemplateSyntaxError, because the dictionary is defined inside the class.

How do I access this dictionary instance attribute of this class within my template?[/INST]