How to use for loop in django email template

On my website, email is sent to the admin email address whenever a user places an order. The problem I am facing, I cannot get for loop working in the email template. How can I use for loop to loop through the products ordered by the user, and display those products in the email. Below is my code

email.html

    {% if order %}
    <h2> Food Ordered</h2>
  <table style="border:1px solid black">
    {% for obj in products %}
    <th style="border:1px solid black">Name</th> 
    <th style="border:1px solid black">Quanity</th>
    <th style="border:1px solid black"> Amount</th>

    <tr>
        <td style="border:1px solid black">
          {{obj.food.name}}
        </td>
        <td style="border:1px solid black">
          {{obj.quantity}}
        </td>
        <td style="border:1px solid black">{{obj.amount}}</td>
    </tr>
    {% endfor %}
    {% endif %}

I want to be able to loop products in the email template

order.cart is the cart shopping object of the user
def reservationEmail(order):
            
    context={
        'order':order.cart,
         'products':order.cart.foods.all(),
            'name':order.name,
            'number':order.number,
            'date':order.datetime ,
            'seats':order.seats,
            'OrderId':order.orderid,
            'total':order.sumamount,
            'quantity':order.reserved.count() 

                }
    template = get_template('home/email.html')
    mail_subject='Reservation/catering made'
    content = template.render(context)
    to_email='usereamil@gmail.com'
    email=EmailMultiAlternatives(mail_subject,content,to=[to_email])
    email.attach_alternative(content, "text/html")
    email.send()
Back to Top