Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def book_page(request, pk):
- # Get book
- i_book = get_object_or_404(Book, pk=pk)
- # Get book text
- book = i_book.full_text.split()
- # On 1 page words
- paginator = Paginator(book, settings.COUNT_WORDS)
- # Get page
- page = request.GET.get('page')
- # Check on int(page)
- if not isinstance(page, int):
- if isinstance(page, str) and page.isdigit():
- page = int(page)
- pages = paginator.page(page)
- else:
- # if page != int -> open first page
- pages = paginator.page(1)
- return render(request, 'reader/view.html', {'book': i_book, 'pages': pages})
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement