For all those ligthning fast shop users. I'm trying to implement my own first page view that will list al开发者_开发技巧l products from shop ( under '/' address). So I have a template :
{% extends "lfs/shop/shop_base.html" %}
{% block content %}
<div id="najnowsze_produkty">
<ul>
{% for obj in objects %}
<li>
{{ obj.name }}
</li>
{% endfor %}
</ul>
</div>
{% endblock %}
and then I've edited main shop view :
from lfs.catalog.models import Category
from lfs.catalog.models import Product
def shop_view(request, template_name="lfs/shop/shop.html"):
products = Product.objects.all()
shop = lfs_get_object_or_404(Shop, pk=1)
return render_to_response(template_name, RequestContext(request, {
"shop" : shop, "products" : products
}))
but it just shows nothing. When I do Product.objects.all() query in shell I get results. Any ideas what could cause the problem ? Maybe I should filter products with 'active' status only ? But I'm not sure if it can influence all objects in any way.
Your problem seems to be that you're calling the context variable products
in your view code, then referring to it as objects
in your template. Fix them to reference the same name, and you should be good to go.
精彩评论