From f99300eecfd92abe9b7b442456694950fb3c54fa Mon Sep 17 00:00:00 2001 From: Patrick Canterino Date: Sun, 23 Jan 2022 22:02:33 +0100 Subject: [PATCH] Do pagination only if there is more than one page --- notes/templates/note_list.html | 20 +++++++++++--------- notes/views.py | 4 +++- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/notes/templates/note_list.html b/notes/templates/note_list.html index e77bce0..f1f5ee5 100644 --- a/notes/templates/note_list.html +++ b/notes/templates/note_list.html @@ -9,13 +9,15 @@

No notes

{% endfor %} - + {% if page_count > 1 %} + + {% endif %} {% endblock %} \ No newline at end of file diff --git a/notes/views.py b/notes/views.py index a0a82bc..793f9ed 100644 --- a/notes/views.py +++ b/notes/views.py @@ -17,10 +17,12 @@ def note_list(request): page_number = int(request.GET.get('page')) except: pass + + page_count = paginator.num_pages notes_page = paginator.get_page(page_number) - return render(request, 'note_list.html', {'notes_page': notes_page, 'notes_count': notes_count, 'pages': paginator, 'page_number': page_number}) + return render(request, 'note_list.html', {'notes_page': notes_page, 'notes_count': notes_count, 'pages': paginator, 'page_number': page_number, 'page_count': page_count}) def note_detail(request, note_slug): note = get_object_or_404(Note, slug=note_slug, status=1) -- 2.34.1