Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

     <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 %}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading