From: Patrick Canterino Date: Sun, 23 Jan 2022 21:02:33 +0000 (+0100) Subject: Do pagination only if there is more than one page X-Git-Url: https://git.p6c8.net/pcdenotes.git/commitdiff_plain/f99300eecfd92abe9b7b442456694950fb3c54fa Do pagination only if there is more than one page --- 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)