I am working on an implementation of an online shop using cartridge & mezzanine. I would like to include a "featured products" section using a category from cartridge's shop (product_category). I have created a test category, populated it with entries and am trying to view it from the homepage but it doesn't return anything. What should i be doing instead?
index.html
{% with category as "featured" %}
{% for product in products.object_list %}
(just using the category.html product display html for now)
views.py
def index(request):
products = Product.objects.all()
context = {'products': products}
return render(request, 'index.html', context)
Your code in index.html:
means treat variable
categoryas string literals (are you sure that this is what you want?), so you will unable to use variablefeaturedafter this statement.Next, according to your code, you have
productsvariable (and this is QuerySet) in your context, so value products.object_list will give nothing, as a QuerySet object do not haveobject_listattribute. Maybe what you want in this line is{% for product in products %}You may publish more code to clarify situation.