Messages and Pagination

Messages survive a redirect. After a successful save you redirect, which means anything you wanted to say is gone. Django's messages framework stores it in the session and shows it on the next page.

messages.success(request, "Post published."), then render them in the base template so every page can show them without thinking about it.

Pagination is not optional. A list view that fetches everything works beautifully with twelve rows and falls over at twelve thousand. Add it before you need it, because retrofitting it means changing the view, the template and every link.

Paginator in a function view, or paginate_by on a ListView. Then make sure the page links keep any existing filter in the query string, which is the part people get wrong.

Mark this lesson complete

Signed in, your progress follows you to every device.

Next: Practice Test →
← Back