Page of a book

Report a typo

Some users prefer to read a book page by page. Create the handler to serve a page by the request.

You can get the n_page variable from the **kwargs argument with the number of the page to show: 1, 2, 3 Store the page content to the context by the key content.

Use the predefined book dictionary with pages you will show to the user and render the template defined in file book/templates/book/page.html.

By default, Django looks for templates in all of your <application_name>/templates directories, so do not include book/templates in the template path.
Write a program in Python 3
from django.views.generic.base import TemplateView

book = {
'Page 1': 'This is the cat',
'Page 2': 'That killed the rat',
'Page 3': 'That ate the malt',
'Page 4': 'That lay in the house that Jack built.',
}


class PageView(TemplateView):
def get_context_data(self, **kwargs):
...
___

Create a free account to access the full topic