Complete the code to import the generic DetailView class from Django.
from django.views import [1]
The DetailView class is part of Django's generic views module, so you import it from django.views.generic.
Complete the code to define a DetailView for a model named Book.
class BookDetailView([1]): model = Book
To create a detail page for a single object, you subclass DetailView.
Fix the error in the URL pattern to use the DetailView correctly for BookDetailView.
path('book/<int:pk>/', [1].as_view(), name='book-detail')
as_view()The URL pattern for a detail page must use the DetailView subclass, here BookDetailView.
Fill both blanks to customize the template name and context object name in the DetailView.
class BookDetailView(DetailView): model = Book template_name = '[1]' context_object_name = '[2]'
The template_name is usually the HTML file name, and context_object_name is the variable name used in the template to access the object.
Fill all three blanks to override the get_context_data method to add extra data to the template context.
class BookDetailView(DetailView): model = Book def get_context_data(self, **kwargs): context = super().[1](**kwargs) context['[2]'] = 'Extra info' return context template_name = '[3]'
To add extra data to the template, override get_context_data, call the parent method, add your data to the context dictionary, and return it. The template name is set as usual.