Unable to Pass Django Context Data to HTML View

Can anybody please tell me how I can pass context data to view. I get nothing in HTML page.

views.py def cart(request): if request.method == 'POST': return redirect('index')

    if request.method == 'GET':
        # Recieve local storage product in post_id varibale
        post_id = request.GET.get('get_cart')
        cat_product = Product.objects.filter(id=.11)
        if post_id is not None:
        # Fomrat and remove { } and " from  post_id string
            post_id = post_id.replace('{','')
            post_id = post_id.replace('}','')
            post_id = post_id.replace('"','')
            print("The Id is", post_id )
        # Find ':' in string and get the value of id in cart_prod_index
            index =0
            while index < len(post_id):
                index = post_id.find(':', index)
                if index == -1:
                local_storage_prod_id = post_id[index-1]

                # '|' operator is used to append the queryset result

                cat_product = cat_product | Product.objects.filter(id=local_storage_prod_id)
        return render(request, "cart.html" ,{"x":cat_product,})

In cart.html

 {% for search in x %}
            {% endfor %}

Please tell How I can get my query set in HTML page

Back to Top