0

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.

McCzajnik
  • 163
  • 1
  • 12
  • I also tried to override template_name in BookListView just to check whether I can but it also did not work. I do not have a clue why. I tried using both name and myapp/path/to/template.html - without any efect – McCzajnik May 17 '17 at 11:30
  • Is your `booksearch_list.html` in the same folder as `book_list.html`? – doru May 17 '17 at 11:36
  • yes. (however) I was wondering if the reason is that django displays first template it finds but I tried to use names that are alphabetically prior - with no success. – McCzajnik May 17 '17 at 11:42
  • what is the structure of your app's `templates` folder? – doru May 17 '17 at 11:45
  • ../appname/templates/appname/. I keep index.html and base html file (which is extended by templates) directly in 'templates' folder everything else is in templates/appname/. – McCzajnik May 17 '17 at 11:54
  • Then you should have `template_name='appname/booksearch_list.html'` in your `BookSearchListView` – doru May 17 '17 at 11:56
  • Yes it should. Thank you! – McCzajnik May 17 '17 at 12:09

1 Answers1

2

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'
doru
  • 9,022
  • 2
  • 33
  • 43