Search code examples
pythondjangourlpaginationurl-pattern

Pagination with URL path or the query parameters


I am working on writing a blog and came across two different alternatives on the internet for making pagination. I couldn't decide which to use. Url types are like ;

blog/page/2

blog/?page=2

Does one of these have an advantage over the other?


Solution

  • Best practices are that path parameters are used to identify a specific resource, and query parameters filter or sort that resource.

    If you are adding a pagination with articles, it would be ideal to use query parameters to sort through the articles. It is common for this query parameter to be referred to as offset, as you would be filtering through your articles.

    So for example if you had 100 articles you've posted, and you want to display 10 articles per pagination page, and you were on page 2 of 10 in your pagination, your offset query parameter would be ?offset=10 because you would be filtering for articles 10-19 to display. (because articles 0-9 were displayed on your first pagination page)

    This offset query parameter would increase by 10 every pagination page you increase, then filtering to the next 10 articles.