Reputation: 47
I'm receiveng this an error and I can't figure out why:
TemplateDoesNotExist at /products/
products/product_list.html
My code:
#from django.views import ListView
from django.views.generic import ListView
from django.shortcuts import render
# Create your views here.
from .models import Product
class ProductListView(ListView):
queryset = Product.objects.all()
tempalate_name = "products/list.html"
def get_context_data(self, *args, **kwargs):
context = super(ProductListView, self).get_context_data(*args, **kwargs)
print(context)
return
def product_list_view(request):
queryset = Product.objects.all()
context = {
'qs': queryset
}
return render(request, "products/list.html", context)
As you can see, I have nowhere mentioned a path: products/product_list.html
, I'm using products/list.html
.
How can I troubleshoot this issue?
Upvotes: 1
Views: 210
Reputation: 16485
It seems to me that you have a spelling error in tempalate_name
. Try changing
tempalate_name = "products/list.html"
to
template_name = "products/list.html"
Does that help?
Looking at the ListView
docs and the example on that page it seems that the default template name is model_name
+ _list.html
; I suspect that is why Django was looking for a product_list.html
template.
Upvotes: 3