0

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
1
  • ANSWERED: The url needed to be just
    – Scott
    Dec 17, 2014 at 7:59

2 Answers 2

1

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

1
  • Ah, but I would like to use class-based views, as they do in the docs.
    – Scott
    Dec 17, 2014 at 7:37
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.