django-pagination
django-pagination copied to clipboard
Broken except clause in paginate() causes 500s on invalid pages when used with a generic view
The except clause wrapping all of paginate() says "except KeyError, AttributeError:". This is broken (needs parens), so AttributeErrors are not actually caught. The symptom of this is that if you use pagination in a template rendered by generic view, and request an invalid page, you get a 500 from an AttributeError in the line "page_range = paginator.page_range".
This only shows up if you use a generic view because a generic view will set the context var "paginator" to None. Without the generic view you get a KeyError two lines earlier, which is caught by the except clause.
Fix for this is in my fork: http://github.com/carljm/django-pagination/commit/2a44e0ac284e3f1ad0c8a7281344674e34a42718
+1 I keep getting this error
File ".../pagination/templatetags/pagination_tags.py", line 134, in paginate
page_range = paginator.page_range
AttributeError: 'NoneType' object has no attribute 'page_range'
The except statement does not catch it! I have had to repackage the patched version in order to use in production and is available if anyone is interested
pip install django-pagination==1.0.8 -U --extra-index-url=http://opensource.washingtontimes.com/pypi/
+1
I had the same error in the Listview. I had this one resolved just by adding 'paginate_by = 20' to the arguments in urls.py for a ListView