McCzajnik
McCzajnik

Reputation: 173

override template_name in listview subclass

I have a BookListView which displays all the books in my library. I have also a subclass of BookListView called BookSearchListView. I am trying to override the template by using the template_name variable. But this produces no effect.

views.py

class BookListView(generic.ListView):
   model=Book
   paginate_by=15



class BookSearchListView(BookListView):
   paginate_by=10
   template_name='booksearch_list.html'
   def get_queryset(self):
       pass

urls.py

url(r'^ksiazki/', views.BookListView.as_view(), name='books'),

url(r'^szukaj/', views.BookSearchListView.as_view(), name='search-list-view'),

I tried to override the template_name in views and in urls but in both cases it keeps book_list.html which is default template for BookListViews and not booksearch_list.html.

Upvotes: 0

Views: 2642

Answers (1)

doru
doru

Reputation: 9110

If your booksearch_list.html template is in the templates/appname/ folder then in your BookSearchListView the template_name should be:

template_name='appname/booksearch_list.html'

Upvotes: 2

Related Questions