django-pagination icon indicating copy to clipboard operation
django-pagination copied to clipboard

Broken except clause in paginate() causes 500s on invalid pages when used with a generic view

Open carljm opened this issue 14 years ago • 3 comments

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

carljm avatar Apr 26 '10 22:04 carljm

+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/

justquick avatar May 27 '10 05:05 justquick

+1

denisenkom avatar Nov 05 '13 02:11 denisenkom

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

iamit avatar Mar 05 '16 23:03 iamit