0
我在数据库中列出了两个类别。Satchmo,想要根据所选产品类别更改模板
我想要更改模板(模板>产品> category.html)取决于所选类别。 (这是因为我想更改每个类别的配色方案和标题图像)
我该怎么做?我是否可以更改
def category_view(request, slug, parent_slugs='', template='product/category.html'):
中指定的模板,它位于product.views?
感谢
这是目前我category_view它返回HTTP500错误和无效的语法蟒蛇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))
请看我上面的代码。我尝试了一些类似于你所建议的但不适合我的东西。 – darren 2011-02-26 11:49:43
会有帮助知道为什么。你能发布你的错误消息吗? – marue 2011-02-26 15:03:21
如果你看看我的if语句结尾,你会看到我忘了: – darren 2011-02-27 07:22:27