0

I'm trying to make django-pagination work with django-filter since I'm working with very large tables. But, after implementing it, when I try to do python manage.py runserver, I get a TypeError: TypeError: PaginationMiddleware() takes no arguments

This is what I have done so far:

  1. Installed django-pagination(1.0.7):
pip install django-pagination
  1. Added it in INSTALLED_APPS in settings.py:
INSTALLED_APPS= [....,'pagination',] 
  1. In my TEMPLATES in settings.py:
'OPTIONS':{'context_processors': ['django.template.context_processors.request'],}, 
  1. In MIDDLEWARE in settings.py:
MIDDLEWARE = [...,'pagination.middleware.PaginationMiddleware',] 
  1. In html file:
{% load pagination_tags %}
...
{% autopaginate filter.qs 40 as filter_list %}
{% for f in filter_list %}
...
{% endfor %}
{% paginate %}

I have all this, but when I try to do runserver I get the following error:

File "D..Local\Programs\Python\Python38\lib\site-packages\django\core\handlers\base.py", line 36, in load_middleware
    mw_instance = middleware(handler)
TypeError: PaginationMiddleware() takes no arguments 

Am I missing something here? Any help is appreciated.

Django version: 2.1.13
Python version: 3.8

Edit: I was told in the comments that django_pagination doesn't support the newer Django versions. I have tried dj_pagination and django.core.paginator as well. But I couldn't make django.core.paginator work with django-filter

Sandeep Kumar
  • 2,397
  • 5
  • 30
  • 37
inava
  • 19
  • 8
  • 1
    The last `django-pagination` release [was in 2010](https://pypi.org/project/django-pagination/#history). It won't support recent versions of Django, because of the switch from old-style middleware (`MIDDLEWARE_CLASSES`) to new-style middleware (`MIDDLEWARE`). – Alasdair Nov 15 '19 at 17:06
  • @Alasdair I see. Thanks for that info. I've tried using dj_pagination too. That gave me a bunch of different errors. Do you know of any other alternatives to paginate my results? I also used django.core.paginator but that broke my django-filter – inava Nov 15 '19 at 17:36
  • No, I'm afraid I don't have any recommendations. The answers to [this question](https://stackoverflow.com/questions/44048156/django-filter-use-paginations) might help you. If you want help getting `django.core.paginator` to work, then you should show what you tried and the full traceback of any errors. – Alasdair Nov 15 '19 at 17:42
  • @Alasdair Thanks for that! I just made dj_pagination work! I would've still been stuck at django-pagination if it wasn't for your comment. Thanks :) – inava Nov 15 '19 at 17:53
  • Apparently I'm blocked from answering questions - but if anyone stumbles upon pagination and wants an easy solution, I ended up using dj-pagination. Very easy to use. Here's the [documentation](https://buildmedia.readthedocs.org/media/pdf/dj-pagination/latest/dj-pagination.pdf) – inava Nov 15 '19 at 17:59

0 Answers0