Question

Im trying to find a way to change django default ?page=1 to ?side=1, or maybe better, /side/1

This is my listview:

class EntryListView(ListView):
    context_object_name = "news_list"
    paginate_by = 18
    queryset = Entry.published.all().order_by('-start_publication') 

I have tried like this:

urlpatterns = patterns('',
    url(r'^/side/(?P<page>\d+)/$', 'news.views.EntryListView'),
    url(r'^$', EntryListView.as_view(), name="news"),
)

But this does not work.

Was it helpful?

Solution

To change ?page=1 to ?side=1 you can add the page_kwarg attribute to your class.

class EntryListView(ListView):
    context_object_name = "news_list"
    paginate_by = 18
    queryset = Entry.published.all().order_by('-start_publication')
    page_kwarg = 'side'

There is no reason that that /side/1/ would not match your URL pattern without overriding the page_kwarg, maybe you missed the trailing slash while testing?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top