[Django]-Django Paginator raising TypeError


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.


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

you must convert string to int

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

you can do it. Both of them runs.

Leave a comment