Description
In src/blog/views.py, the blog_index() view sets last_page in the context using page.has_previous(), which is semantically inverted. has_previous() returns True when there are pages before the current one — which is true for every page except the first. This means last_page is False only on the first page and True on all others, which is the opposite of what the variable name suggests.
Location
File: src/blog/views.py
Function: blog_index()
Branch: develop
Current Code
context = {
"next_page_number": page_number + 1,
"posts": posts,
"PREVIEW_SIZE": PREVIEW_SIZE,
"last_page": page.has_previous(), # WRONG: True when NOT on first page
"total_pages": paginator.num_pages,
"page_url": "/memories/",
"blog_categories": Category.objects.all(),
}
Problem
page.has_previous() returns True when there are pages before the current page — i.e., for every page except page 1.
- The variable
last_page is presumably used in the template to detect whether the user has reached the final page (to hide a "load more" button or show an end-of-feed indicator).
- With the current logic,
last_page is always True except on page 1, causing the template to think the feed has ended on the second page.
Suggested Fix
"last_page": not page.has_next(),
This correctly sets last_page to True only when there are no more pages to load.
Severity
Medium — Causes incorrect pagination UI behavior: the "load more" button or infinite scroll may stop working prematurely after the first page.
Description
In
src/blog/views.py, theblog_index()view setslast_pagein the context usingpage.has_previous(), which is semantically inverted.has_previous()returnsTruewhen there are pages before the current one — which is true for every page except the first. This meanslast_pageisFalseonly on the first page andTrueon all others, which is the opposite of what the variable name suggests.Location
File:
src/blog/views.pyFunction:
blog_index()Branch:
developCurrent Code
Problem
page.has_previous()returnsTruewhen there are pages before the current page — i.e., for every page except page 1.last_pageis presumably used in the template to detect whether the user has reached the final page (to hide a "load more" button or show an end-of-feed indicator).last_pageis alwaysTrueexcept on page 1, causing the template to think the feed has ended on the second page.Suggested Fix
This correctly sets
last_pagetoTrueonly when there are no more pages to load.Severity
Medium — Causes incorrect pagination UI behavior: the "load more" button or infinite scroll may stop working prematurely after the first page.