Проблема с рендерингом объектов на шаблоне Django
Я пытаюсь сделать фильтр на моем сайте электронной коммерции. Я получаю данные с помощью json от пользователя и фильтрую товары в файле views.py. Нет никаких ошибок, и я могу видеть отфильтрованные товары в консоли. Однако я не могу отобразить товары в шаблоне. Он не выдает никаких ошибок. Он просто не отображается. views.py
def Products(request):
data = cartData(request)
cartItems = data['cartItems']
order = data['order']
items = data['items']
products = Product.objects.all()
gender = Gender.objects.all()
categories = Category.objects.all()
product_types = ProductType.objects.all()
try:
data = json.loads(request.body)
productTId = data['productTId']
productVId = data['productVId']
genderId = data['genderId']
genderId = get_object_or_404(Gender, id=genderId)
productVId = get_object_or_404(Category, id=productVId)
productTId = get_object_or_404(ProductType, id=productTId)
filtered_products = Product.objects.filter(typeP=productTId).filter(category=productVId).filter(Gender=genderId)
countFilter=filtered_products.count()
print(filtered_products)
print(countFilter)
return JsonResponse(filtered_products, safe = False)
except:
None
try:
context = {'countFilter':countFilter,'filtered_products':filtered_products,'gender':gender,'categories':categories,'product_types':product_types,'products':products, 'cartItems':cartItems, 'order':order, 'items':items}
except:
context = {'gender':gender,'categories':categories,'product_types':product_types,'products':products, 'cartItems':cartItems, 'order':order, 'items':items}
return render(request, 'product.html', context)
html
{% for product in filtered_products %}
<div class="card">
<div class="card__img">
<picture><source srcset="{{product.imageURL}}" type="image/webp"><img src="{{product.imageURL}}" alt=""></picture>
</div>
<h6 class="card__title">{{product.name}}</h6>
<div class="card__descr">{{product.description}}...
<div class="card__more" onclick="More('{{product.id}}')">подробнее...</div>
</div>
<div class="card__func">
<a class="btn-hover card__button-buy update-cart" data-product="{{product.id}}" data-action="add">В КОРЗИНУ</a>
<div class="card__right">
<div class="card__price" data-product="{{product.id}}">{{product.price}} р</div>
<div class="card__changed-price card__changed-price--card">
<div class="card__changed-btn card__changed-btn--prev card__changed-btn--max increase" data-product="{{product.id}}" data-action="minus"><svg width="8" height="2" viewBox="0 0 8 2" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M1 1L7 1" stroke="#7ABC51" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
</div>
<p class="card__changed-thing" id="quantity" class="quantity" data-product="{{product.id}}">1</p>
<div class="card__changed-btn card__changed-btn--next increase" data-product="{{product.id}}" data-action="plus"><svg width="8" height="8" viewBox="0 0 8 8" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M3 7C3 7.41421 3.33579 7.75 3.75 7.75C4.16421 7.75 4.5 7.41421 4.5 7V4.75H6.75C7.16421 4.75 7.5 4.41421 7.5 4C7.5 3.58579 7.16421 3.25 6.75 3.25H4.5V1C4.5 0.585786 4.16421 0.25 3.75 0.25C3.33579 0.25 3 0.585786 3 1V3.25H0.75C0.335786 3.25 0 3.58579 0 4C0 4.41421 0.335786 4.75 0.75 4.75H3V7Z" fill="#7ABC51"/>
</svg>
</div>
</div>
</div>
</div>
</div>
{% endfor %}
As I mentioned it's not returning any errors and I can see result on the console. But, it's only not showing while I tried to render it. Hope for your response.