JavaScript
x
20
20
1
{% extends 'base.html' %}
2
3
{% block content %}
4
<hi>Products</hi>
5
<div class="row">
6
{% for products in products %}
7
<div class="col">
8
<div class="card" style="width: 70rem;">
9
<img src="{{ products.image_url }}" class="card-img-top" alt="...">
10
<div class="card-body">
11
<h5 class="card-title">{{ products.name }}</h5>
12
<p class="card-text">${{ products.price }}</p>
13
<a href="#" class="btn btn-primary">Add to Cart</a>
14
</div>
15
</div>
16
</div>
17
{% endfor %}
18
</div>
19
{% endblock %}
20
Is there a problem with this code
I tried reformatting the code, by replacing the products.url into the alt brackets. But it was what i typed on in the brackets that showed up.
Advertisement
Answer
I am not exactly sure what your problem is but I see problem in code, try replacing:
JavaScript
1
2
1
{% for products in products %}
2
to
JavaScript
1
2
1
{% for single_product in products %}
2
and then update this lines with new variable name single_product
JavaScript
1
4
1
<img src="{{ single_product.image_url }}" class="card-img-top" alt="...">
2
<h5 class="card-title">{{ single_product.name }}</h5>
3
<p class="card-text">${{ single_product.price }}</p>
4
By using the same variable name you are overriding it