python - What is the best way to get row_num in django? -


what best way row_num in django ? can use variable counter in django template tags ?

{% o in objects %} <tr>   <td>{{ row_num }}</td>   <td>{{ o.first_name }}</td>   <td>{{ o.last_name }}</td> </tr> {% endfor %} 

thanks in advance.

you can use forloop template tag :

  • forloop.counter -> current iteration of loop (1-indexed)
  • forloop.counter0 -> current iteration of loop (0-indexed)
  • forloop.revcounter -> number of iterations end of loop (1-indexed)
  • forloop.revcounter0 -> number of iterations end of loop (0-indexed)
  • forloop.first -> true if first time through loop
  • forloop.last -> true if last time through loop
  • forloop.parentloop -> nested loops, loop "above" current one

Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -