Django:设置模板_name不';不能在基于类的视图中工作
我有一个Django:设置模板_name不';不能在基于类的视图中工作,django,django-views,django-class-based-views,Django,Django Views,Django Class Based Views,我有一个产品列表视图: class ProductListView(ListView): model = Product template_name = 'products/product_list.html' context_object_name = 'products' 我试图创建另一个列表视图列表产品: class VoteView(ListView): model = Product template_name = 'recommendatio
产品列表视图
:
class ProductListView(ListView):
model = Product
template_name = 'products/product_list.html'
context_object_name = 'products'
我试图创建另一个列表视图
列表产品
:
class VoteView(ListView):
model = Product
template_name = 'recommendation/rec_product_list.html'
context_object_name = 'products'
但当我试图在浏览器中访问VoteView
时,出现了错误:它呈现了product\u list.html
,而不是rec\u product\u list.html
所以我调试了它,发现get\u template\u names()
返回,
['recommendation/rec_product_list.html','products/product_list.html']
我可以通过插入以下代码来修复此问题:
def get_template_names(self):
return ['recommendation/rec_product_list.html']
但是我想知道是否有比这更好的方法
谢谢默认情况下,如果应用程序名称为
产品
,则您的列表视图
将自动分配产品/product\u list.html
。错误是否为TemplateDoesNotExist?您使用的是哪个版本的Django?