Auntoincrementable in HTML

2

I have the following html code and what I need is for tb_header1 to increase the values of i , j en 1, and rangos go incrementing 1 the value of a (in each for ).

{% for atributo in tb_header %}

 <td class="sorting" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" aria-label={{ atributo }}": activate to sort column ascending" style="width: 254px;">{{ atributo }}</td>

<table>
  <tr>
    <td>Nro </td>
    <td>Label</td>
    <td>Count</td>
  </tr>
  <tr>                                                    
    <td>{{tb_header1.i.j}}</td>
    <td>{{rangos.a}}</td>
  </tr>
</table>
{% endfor %}
    
asked by user6905478 25.11.2016 в 04:53
source

2 answers

1

You could use a Filter , to perform the operation of Sum (add) (+ 1) to any variable within the templates.

Example (In your View)

def index(request):
    lista = [1, 2, 3, 4, 5 ];
    return render_to_response('index.html', {'lista':lista})

(In your Template)

{% for atributo in lista %}
   {{ atributo |add:1 }}
{% endfor %}

Exit

2 3 4 5 6
    
answered by 25.11.2016 в 06:00
1

I do not know if you know the foorloop object in the Django templates. It is an object that is created automatically in the scope of a for loop and its main properties are:

  • foorloop.counter : Starts at 1 and increases at each iteration.
  • foorloop.counter0 : Start at 0 and increase at each iteration.

It has more properties that you can review in:

link

{% for item in list %}
    {# Esto imprimira las veces que ha iterado el bucle for, comenzando con el valor 1  #}
    {{ foorloop.counter }}
{% endfor %}

I hope you find it useful.

Good luck and greetings!

    
answered by 26.01.2017 в 16:40