Django

27 views
Skip to first unread message

Max

unread,
Oct 18, 2011, 11:02:47 AM10/18/11
to google-a...@googlegroups.com
Hi,
I suppose for who knows it, this request is really easy. But It's making me crazy and I can't find documentation in the Django site (or I can't understand it).
I'm building an array to be used in a javascript. I need the var "contatore" to be 0 then 1, 2, 3... I need to +1 each time starting by 0. 
Normally I have only to declare the var =0 out the for and the just var = var +1 inside the for. But in Django I can't understand which is the sybtax to do it.
Please help, I need only this to close a project!!!!
This is my code:

{% for elemento in risultati %}
indirizzi[{{ contatore }}]="{{ elemento.indirizzo }}, {{ elemento.citta }} {{ elemento.nazione }}";
descrizioni[{{ contatore }}]="{{ elemento.nome }}";
informazioni[{{ contatore }}]="Nome: {{ elemento.nome }} "
{% endfor %}


Max

Matt Jibson

unread,
Oct 18, 2011, 12:09:49 PM10/18/11
to google-a...@googlegroups.com
You need to user {{ forloop.counter }}.
https://docs.djangoproject.com/en/1.2/ref/templates/builtins/#for

> --
> You received this message because you are subscribed to the Google Groups
> "Google App Engine" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/google-appengine/-/yddhjx8qTvoJ.
> To post to this group, send email to google-a...@googlegroups.com.
> To unsubscribe from this group, send email to
> google-appengi...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/google-appengine?hl=en.
>

Max

unread,
Oct 18, 2011, 12:13:17 PM10/18/11
to google-a...@googlegroups.com
Thanks!!!! It's working well!!!!!
Reply all
Reply to author
Forward
0 new messages