user2876703
user2876703

Reputation: 63

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 ?

Upvotes: 6

Views: 3477

Answers (1)

mariodev
mariodev

Reputation: 15484

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.

Upvotes: 14

Related Questions