I have an array of names in python, which I would like to display using Django templates. I know that tags can be used that support for loops, but they have a unique syntax which I am unfamiliar with.
Also I do not want to use instance.0, instance.1 and so on. I need to be scalable for any size array
Django Template code
(:,
{% for name in instance %}
{{instance}}
{%endfor%}
My name is {{my_name}}.
(:,
Python code
from django.template import Template, Context
from django.conf import settings
settings.configure()
t=Template(The above section)
dtype={'names': ['name','offset'],
'formats':['U20,U20']
}
instance = np.zeros(5,dtype='U20')
instance[0]=('John')
instance[1]=('Tim')
instance[2]=('Sarah')
name="adrian"
c=Context({"instance":instance, "my_name":name})
print(t.render(c))
Current output
(:,
['John' 'Tim' 'Sarah' '' '']
['John' 'Tim' 'Sarah' '' '']
['John' 'Tim' 'Sarah' '' '']
['John' 'Tim' 'Sarah' '' '']
['John' 'Tim' 'Sarah' '' '']
My name is adrian.
).
Desired output
(:,
i=0
[John]
[Tim]
[Sarah]
My name is adrian.
).
{{instance}}, output{{name}}