Q:

Django context/template : Rendering multiple results

I have this code that I want it to be able to return multiple products. Now it only return the last one.
I think it is because the variables are being overwritten but I don't know other ways to fix it.
def result(request):

    rawquery = request.GET.get('q') #gets the product name to search from a form
    Product_set = Product.objects.filter(name__icontains=rawquery).distinct()
    for product in Product_set:
        name = product.name
        id = product.id
        store_name = product.store_name

        Price_set = Scan.objects.filter(product=id)
        for price in Price_set:
            current_price = price.price

        context = {
            'name': name,
            'store_name': store_name,
            'price': current_price,
            'query': rawquery
        }

        return render(request, 'result.html', context)

This is the template
%  {extends 'base.html' %}

  {%  block content %}

    <h1>Results for {{ query }} </h1> 

    <p> {% if name %} {{name}} {% else %} None {% endif %} | {% if store_name %} {{store_name}} {% endif %} | {% if price %} {{price}} {% endif %} </p>

  {% endblock content %}

A:

you have to append products to a list: 
def result(request):

    rawquery = request.GET.get('q') #gets the product name to search from a form
    Product_set = Product.objects.filter(name__icontains=rawquery).distinct()
    products = []
    for product in Product_set:
        price = Scan.objects.filter(product=product.id).first()

        products.append({
            'name': product.name,
            'store_name': product.store_name,
            'price': price.price
        })

    return render(request, 'result.html', {'query': rawquery, 'products': products})

you can now loop products here:
{% extends 'base.html' %}

{%  block content %}

<h1>Results for {{ query }} </h1> 
{% for product in products %}
<p> {{product.name}} | {{product.store_name}} | {{product.price}} </p>
{% endfor %}

{% endblock %}

