【发布时间】:2023-04-11 06:53:01
【问题描述】:
我是 django 的新手。 我有一个 django 应用程序,其中存储按“X”和“Y”分类的产品。
views.py
...
class CartListView(ListView):
template_name = 'checkout/list.html'
context_object_name = 'product_list'
def get_queryset(self):
return Product.objects.filter(category__slug='X') | Product.objects.filter(category__slug='Y')
def get_context_data(self, **kwargs):
context = super(CartListView, self).get_context_data(**kwargs)
context['minicurso'] = get_object_or_404(Category, slug='X')
context['pacotes'] = get_object_or_404(Category, slug='Y')
return context
...
在我的views.py 中,我按您的分类筛选了这个产品。
问题是,我试图在页面顶部呈现类别“X”中的产品,并在它们之间呈现文本类别“Y”中的产品。我该怎么做?
list.html
{% for category in product_list %}
{{ category.name }}
{% endfor %}
<p>
Any text
</p>
{% for category in product_list %}
{{ category.name }}
{% endfor %}
【问题讨论】:
标签: python django django-templates django-queryset