Exercise 3: Why rstrip('/') Is Necessary — Possible Solution ==================================================================== HOW full_path WAS BUILT IN CHAPTER 2 ------------------------------ Per Chapter 2's own save() method, full_path is built as either just self.slug (for a top-level page) or f"{self.parent.full_path}/{self.slug}" (for anything nested) - neither branch ever appends a trailing slash. A stored value looks like "programming/python", never "programming/python/". WHY A MISMATCH WOULD OCCUR WITHOUT rstrip('/') ------------------------------ Per this chapter, Django's own convention appends a trailing slash to normalized URLs, so an actual incoming request typically arrives as something like /programming/python/ - and the path converter would capture full_path as "programming/python/", WITH the trailing slash, exactly as it appeared in the URL. Querying Page.objects.get(full_path="programming/python/") against a stored value of "programming/python" (no trailing slash) would never find a match, for every single page on the site, since the two strings are not identical. WHY rstrip('/') FIXES IT ------------------------------ full_path.rstrip('/') strips any trailing slash off the incoming URL value before the query runs, converting "programming/python/" back into "programming/python" - now matching the exact, no-trailing-slash format every stored full_path was built in back in Chapter 2. WHY THIS WORKS AS AN ANSWER ------------------------------ It correctly recalls that Chapter 2's save() method never appends a trailing slash to full_path, correctly explains that Django's own URL convention would otherwise deliver a trailing-slash version to the view, and correctly explains that rstrip('/') reconciles the two formats before the database query runs.