how to run this code in django template
The template subsystem has some special constructs built into the for/endfor block that allows you to access the current index of the loop without having to call enumerate
.
{% for j in a %} {{ forloop.counter0 }}, {{ j }}{% endfor %}
While this snippet solves your immediate problem, if you're expecting to have access to Python builtins and other Python constructs inside your Django templates, you may be misunderstanding the sandbox that it provides/enforces.
{% for item in a %} {{ forloop.counter }}, {{ item }}{% endfor %}