Skip to content

blog_index view has inverted last_page logic using has_previous() instead of not has_next() #857

@vjpixel

Description

@vjpixel

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    backendbugSomething isn't workingpriority: highHigh priority - should be addressed soonpriority: mediumMedium priority - standard priority

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions