Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
carljm opened this issue Apr 26, 2010 · 3 comments

Comments

@carljm
Copy link
Contributor

carljm commented Apr 26, 2010

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

@justquick
Copy link

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

@denisenkom
Copy link

+1

@iamit
Copy link

iamit commented Mar 5, 2016

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants