Opened 6 years ago

Closed 6 years ago

#13986 closed (fixed)

When using the object_list you can not pass paginate_by in the url

Reported by: d0ugal Owned by: d0ugal
Component: Generic views Version: 1.2
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


In trying to vary the page size in the url, we tried to pass in the paginate_by in the url. The Pagination class does not convert arguements into ints and fails.

This is the documented behaviour however the view would be more generic if this could be varied like this.

This can be reproduced by adding the following to your

urlpatterns += patterns('django.views.generic.list_detail',
    (r'^object_list/(?P<paginate_by>[0-9]?)/page(?P<page>[0-9]+)/$', 'object_list', object_list_dict),

A request to this url will cause the following traceback

ERROR: test_finds_past (regressiontests.views.tests.generic.object_list.ObjectDetailTest)
Traceback (most recent call last):
  File "/Users/dougal/Django/django_src/tests/regressiontests/views/tests/generic/", line 17, in test_finds_past
    response = self.client.get('/views/object_list/%s/page1/' % paginate_by)
  File "/Users/dougal/Django/django_src/django/test/", line 290, in get
    response = self.request(**r)
  File "/Users/dougal/Django/django_src/django/core/handlers/", line 100, in get_response
    response = callback(request, *callback_args, **callback_kwargs)
  File "/Users/dougal/Django/django_src/django/views/generic/", line 60, in object_list
    page_obj =
  File "/Users/dougal/Django/django_src/django/core/", line 41, in page
    if top + self.orphans >= self.count:
TypeError: coercing to Unicode: need string or buffer, int found


the object_list generic view already converts the page argument to an int. It would then make sense to convert paginate_by in the same place in the view

Attachments (2)

object_list_paginate_by.diff (4.3 KB) - added by d0ugal 6 years ago.
object_list_paginate_by.txt (4.3 KB) - added by d0ugal 6 years ago.
Added a plain text version that trac should hopefully be able to display.

Download all attachments as: .zip

Change History (5)

comment:1 Changed 6 years ago by d0ugal

  • Needs documentation unset
  • Needs tests unset
  • Owner changed from nobody to d0ugal
  • Patch needs improvement unset

Changed 6 years ago by d0ugal

Changed 6 years ago by d0ugal

Added a plain text version that trac should hopefully be able to display.

comment:2 Changed 6 years ago by d0ugal

  • Has patch set

I've attached a patch which converts the paginate_by value into an int. This is built on top of a patch added to #13897 (which adds tests for object_list) and thus needs to be applied after the patch in #13897.

I added a .txt version as trac fails to display the diff correctly.

comment:3 Changed 6 years ago by russellm

  • Resolution set to fixed
  • Status changed from new to closed

Function-based generic views were deprecated by the introduction of class-based views in [14254]. Class-based views should solve this problem.

Note: See TracTickets for help on using tickets.
Back to Top