Scott
Scott

Reputation: 4331

Django pagination url parameters

I am trying to use Django's pagination for class based views, as described in the docs.

In my urls.py, I have:

url(r'^clues/page(?P<page>[0-9]+)/$', views.ClueIndexView.as_view())

The docs tell me I should be able to access this with an url like:

/clues/?page=3

But that always fails with a 404.

Instead, /clues/page3/ works....but that isn't what I want...I want to use ?page=3. What am I doing wrong?

EDIT: I'm handling it with a class-based view, like so:

class ClueIndexView(ListView):
    context_object_name = 'clue_list'
    template_name = 'clue_list.html'
    queryset = Clue.objects.all()
    paginate_by = 10

Upvotes: 0

Views: 1074

Answers (2)

Scott
Scott

Reputation: 4331

My url was bad. I found the docs to be a bit confusing. My url needs to be just

url(r'^clues/$', views.ClueIndexView.as_view()

Works now.

Upvotes: 0

Sardorbek Imomaliev
Sardorbek Imomaliev

Reputation: 15400

You should do something like this:

url(r'^clues/$')
def clues(request):
    if request.method == 'GET':
        page = request.GET.get('page')
...

all GET info passed after '?' like your page '?page=n' stored in request.GET dictionary

Upvotes: 1

Related Questions