Answer the question
In order to leave comments, you need to log in
Problem with for function in django?
The fact is that I seem to be sending everything correctly to html
. But the for function, in principle, does not work 4 times (so many product positions), and the product names are not indicated,
it does not display anything
when I call {{ item }}, that's what it gives
"(QuerySet [Product: 2500.56 Gain Bolic 6000, Product: 35000.43 Fuioiuyt, Product: 4500.00 Gain Bolic 6000, Product: 9000.00 vhjvkkhvhjjhk],)"
class Product(models.Model):
name = models.CharField(max_length=64, blank=True, null=True, default=None)
price = models.DecimalField(max_digits=10, decimal_places=2, default=0)
description = models.TextField(blank=True, null=True, default=None)
is_active = models.BooleanField(default=True)
created = models.DateTimeField(auto_now_add=True, auto_now=False)
updated = models.DateTimeField(auto_now_add=False, auto_now=True)
def __str__(self):
return "%s %s" % (self.price , self.name)
class Meta:
verbose_name = "Товар"
verbose_name_plural = "Товары"
def home(request):
item = (Product.objects.filter(is_active=True)),
return render(request, 'landing/home.html', item.name.all())
{% block content %}
{% include 'slider.html' %}
{% include 'navbar.html' %}
<div class="section">
<div class="container">
<div class="row">
{{item}}
{% for name in item %}
<div class="col-lg-3">
<div class="view-item">
<span>{{ item.name }}</span>
</div>
</div>
{% endfor %}
</div>
</div>
</div>
</div>
{% include 'footer.html' %}
{% endblock %}
Answer the question
In order to leave comments, you need to log in
The context must be a dictionary.
def home(request):
item = Product.objects.filter(is_active=True)
return render(request, 'landing/home.html', {"item": item})
item.name.all()
? Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question