我的数据库中列出了两个类别。
我想根据选择的类别更改模板(templates>product>category.html)。(这是因为我想更改每个类别的配色方案和标题图像)
我怎样才能做到这一点?我可以更改在
def category_view(request, slug, parent_slugs='', template='product/category.html'):
哪个在 product.views 中?
谢谢
这是我当前的 category_view,它返回一个 http500 错误和一个无效的语法 python django 错误。
def category_view(request, slug, parent_slugs='', template='product/category.html'):
"""Display the category, its child categories, and its products.
Parameters:
- slug: slug of category
- parent_slugs: ignored
"""
try:
category = Category.objects.get_by_site(slug=slug)
products = list(category.active_products())
sale = find_best_auto_discount(products)
except Category.DoesNotExist:
return bad_or_missing(request, _('The category you have requested does not exist.'))
child_categories = category.get_all_children()
ctx = {
'category': category,
'child_categories': child_categories,
'sale' : sale,
'products' : products,
}
if slug == 'healing-products'
template = 'product/i.html'
if slug == 'beauty-products'
template ='product/category_beauty.html'
index_prerender.send(Product, request=request, context=ctx, category=category, object_list=products)
return render_to_response(template, context_instance=RequestContext(request, ctx))