开发者

Django LFS - custom views

开发者 https://www.devze.com 2022-12-22 14:03 出处:网络
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 :

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消