using boolan in django templates

for item in query_results:
    num +=1
    print num

this will give you 1, 2, 3, 4 etc

I then tried doing this in django templates doing the following

{% for item in query_results %}
<tr>
<td>{{ item.user }}</td>
<td>{{ num|add:"1" }}</td>
</tr>
{% endfor %}

But this only returns 1, 1, 1, 1, 1 etc. This says to me that the 1 isn't being saved to num each cycle. IS this then not a capability of django templates, or am i just doing it wrong.

Answers


Use forloop.counter instead.

{% for item in query_results %}
<tr>
<td>{{ item.user }}</td>
<td>{{ forloop.counter }}</td>
</tr>
{% endfor %}

Need Your Help

Python web hosting: Numpy, Matplotlib, Scientific Computing

python numpy matplotlib scipy

I write scientific software in Numpy/Scipy/Matplotlib. Having developed applications on my home computer, I am now interested in writing simple web applications. Example: user uploads image or audio

XMPPFramework - Delete a registered user account

ios xmpp xmppframework

I am using https://github.com/robbiehanson/XMPPFramework for my iOS chat application.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.