Not bug, my program is just not functioning the way I want it to

I have a list of product with each products having a "pack" feature which can allow users to input any number and then multiplies the number by "food price" of the selected product.

views.py

def food_box_func():
    my_food_box = Food.objects.all()

    append_list_item = []
    for item in my_food_box:
        image = item.image
        food_item = item.food_item
        food_price = item.food_price
        food_slug = item.slug
        list_item = [image,food_item,food_price,food_slug]
        new_list_item = append_list_item.append(list_item)
    return append_list_item

def food_box(request, slug):
    quantity = ""
    total_price = ""
    for item in food_box_func():
        
        if request.method == "POST":
            try:
                quantity = int(request.POST.get("price in pack"))
                print(quantity)
                total_price = quantity*item[2]
                print(total_price)
                return render(request,'payments/pay.html',{'price':total_price,'slug':slug,'quantity':quantity,'total_price':total_price})
            except ValueError:
                return render(request,'food_app/404.html')
        break
        
    return render(request,'food_app/food_box.html',{'item':food_box_func(),'price':total_price,'slug':item[3]})

Here is my food template which is connected to the view above:

<body>
    <div class="container">
    <br><br><h1><center>Food box page!</center></h1><br><br>
    </div>

    {% for message in messages %}
    <div class="alert alert-{{message.tags}} alert-dismissible fade show" role="alert">
    <strong>Message:</strong> {{message}}
    <button type="button" class="close" data-dismissible="alert" aria-label="close">
    <span aria-hidden="True">&times;</span>
    </button>
    </div>
    {% endfor %}


                {% comment %} Each for loop item takes its slug input and directs the user to its particular view on the payment page. 
                {% endcomment %}

                {% if user.is_authenticated %}
                
                {% for item in item %}
                
                <div class="container">
                <a href= "{% url 'payments:payment' price=item.2 slug=item.3 %}"><img src={{item.0.url}} class="img-fluid"></a><br><br>
                <h2>{{item.1|capfirst}}</h2>
                <h3>₦{{item.2}}</h3>
                <button type="submit" class="btn btn-success" onClick="window.location='{% url 'payments:payment' price=item.2 slug=item.3 %}';"><strong>Eat Me!</strong></button><br><br>

                <form action="{#{% url 'payments:payment' price=total_price slug=item.3 %}#}" method="POST">
                  {% csrf_token %}

                <div class="input-group mb-3">
                  <span class="input-group-text">Price in packs</span>
                  <input type="number" class="form-control" name="price in pack"  aria-describedby="price in pack" placeholder="Input numbers between 20 and 100" aria-label="Input numbers between 20 and 500" min="20" max="100">
                  <button type="submit" class="btn btn-success"><strong>Click Me!</strong></button>
                </div>
                </form><br><br><br><br>
                </div>

                {% endfor %}

The above program is working for only the first item but I need it to work for all the products according to user request.

Back to Top