Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django pagination - nice urls

I did pagination in my django projet. Everything works just perfect, but my urls looks terrible, like

host:8000/?page=1 

How to create nice urls like

host:8000/page/2/ or host:8000/2/

I use standard Paginator class via ListView

How to do this w/o third party code ?

like image 738
user2876703 Avatar asked Oct 13 '13 18:10

user2876703


1 Answers

If you define url pattern like this:

url(r'^/page/(?P<page>\d+)/$', 'myapp.views.list_view'),

then ListView will pass page url keyword into paginator.

Notice: Each path segment is supposed to be a valid resource, so it's not clear what you will display on /path/ URL.

Django pagination system assumes that webpages will default to using the URL query, so it's recommended to keep it as a URL query and it's more revealing.

like image 153
mariodev Avatar answered Sep 29 '22 01:09

mariodev