[Django]-Django Paginator raising TypeError

6👍

Try changing this line:

page = request.GET.get('page')

To this:

page = request.GET.get('page', '1')

The problem is you’re getting a parameter that doesn’t exist. Indexing using [] would result in a KeyError, but the get method returns None if it doesn’t exist. The paginator is calling int(None), which fails.

The second parameter to the get method is a default to return if the key doesn’t exist rather than None. I passed '1' which int should not fail on.

-1👍

get = self.request.GET
page = int(get.get('page'))

you must convert string to int
or

 page = int(request.GET.get('page'))

you can do it. Both of them runs.

Leave a comment