Why is my for loop not working in django?

I’m new to Django and I tried to load data into my template using for loop ended up getting the for loop tags written on my template.

Views.py

from django.shortcuts import render
from django.http import HttpResponse

from projet.models import Employe
# Create your views here.

def page(request) : 
    employe = Employe.objects.all()
    return render(request,'hello.html',{'employe':employe})

Html table template

     <table class="table">

            <tr class="tr">
                <th>ID</th>
                <th>Nom et Prenom</th>
                <th>Lundi</th>
                <th>Mardi</th>
                <th>Mercredi</th>
                <th>Jeudi</th>
                <th>Vendredi</th>
                <th>Samedi</th>
                <th>Dimanche</th>
            </tr>

            { % for i in employe % }
              <tr>
                <td>{{ forloop.counter }}</td>
                <td>{{ i.name }}</td>
                <td>{{ i.monday }}</td>
                <td>{{ i.tuesday }}</td>
                <td>{{ i.wednesday }}</td>
                <td>{{ i.thursday }}</td>
                <td>{{ i.friday }}</td>
                <td>{{ i.saturday }}</td>
                <td>{{ i.sunday }}</td>

              </tr>
            { % endfor % }
        </table>

>Solution :

You cant have spaces between your { and your %.

{% for i int ... %}
.....
{% endfor %}

Leave a Reply