Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 67411

Django urls.py: best way to not have a page number in the url for the first page in a list view?

$
0
0

Right now I have a list view that displays 10 posts per page:

The urls would be something like this:

www.example.com/posts/1  (First page with 10 results)
www.example.com/posts/2  (Next page with 10 results)

and my urls.py looks something like this:

path('posts/<int:page>', PostList.as_view(), name='post-list'),

I want to be able to have the first page of posts also visible when there is no number, for example:

www.example.com/posts  (First page with 10 results)

The only way that I have been able to solve this is by adding another line in the urls.py that points to the same view and that has the same name.

path('posts', PostList.as_view(), name='post-list'),
path('posts/<int:page>', PostList.as_view(), name='post-list'),

Is this the appropriate way of doing this or is there a better way?

Many thanks!


Viewing all articles
Browse latest Browse all 67411

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>