Reputation: 156
How do I access the value of tuple through indexing in a template? When i try to do this....django gives me the error : Could not parse the remainder: '[0]' from 'tuple[0]'.
template.html:
{{ tuple[0] }}
views.py:
def fun(request):
tuple=('a','b','c','d')
return render(request,'template.html',{'tuple':tuple})
Upvotes: 5
Views: 4907
Reputation: 22041
Simply access tuple as in code below:
{{ tuple.0 }}
Also consider using django built-in template tags to iterate over your data, see simple usage below:
{% for item in tuple %}
<span>
{{ item }}
</spam>
{% endfor %}
Upvotes: 10