page() takes 1 positional argument but 2 were given

pri

I am trying to design an api for search functionality. Search is based on place name.What i want is localhost:8000/api/v1/rent/search/?format=json&q="california" but i am getting an error which i have attached below enter image description here

{
  "error_message": "page() takes 1 positional argument but 2 were given",
  "traceback": "Traceback (most recent call last):\n\n  File \"/home/tushant/.virtualenvs/rent/lib/python3.4/site-packages/tastypie/resources.py\", line 211, in wrapper\n    response = callback(request, *args, **kwargs)\n\n  File \"/home/tushant/Projects/rentals-v2.1/rentals/api/api.py\", line 102, in get_search\n    page = paginator.page(int(request.GET.get('page', 1)))\n\nTypeError: page() takes 1 positional argument but 2 were given\n"
}

my code for search api is

    from rentals.models import Rental,Gallery
    from django.core.paginator import InvalidPage
    from django.conf.urls import *
    from tastypie.paginator import Paginator
    from tastypie.exceptions import BadRequest
    from tastypie.resources import ModelResource
    from tastypie.utils import trailing_slash
    from haystack.query import SearchQuerySet
     class SearchResource(ModelResource):
        class Meta:
            queryset = Rental.objects.all()
            resource_name = 'rent'

    def prepend_urls(self):
        return [
            url(r"^(?P<resource_name>%s)/search%s$" % (self._meta.resource_name, trailing_slash()), self.wrap_view('get_search'), name="api_get_search"),
        ]

    def get_search(self, request, **kwargs):
        self.method_check(request, allowed=['get'])
        self.is_authenticated(request)
        self.throttle_check(request)

        # Do the query.
        sqs = SearchQuerySet().models(Rental).load_all().auto_query(request.GET.get('q', ''))
        paginator = Paginator(sqs, 20)

        try:
            page = paginator.page(int(request.GET.get('page', 1)))
        except InvalidPage:
            raise Http404("Sorry, no results on that page.")

        objects = []

        for result in page.object_list:
            bundle = self.build_bundle(obj=result.object, request=request)
            bundle = self.full_dehydrate(bundle)
            objects.append(bundle)

        object_list = {
            'objects': objects,
        }

        self.log_throttled_access(request)
        return self.create_response(request, object_list) 

my models.py is

class Rental(models.Model):
        city =  models.CharField(_("City"), max_length=255, blank=False,null=True,
            help_text=_("City of the rental space"))
        place =  models.CharField(_("Place"), max_length=255, blank=False,null=True,
            help_text=_("Place of the rental space"))

    class Gallery(models.Model):
        rental = models.ForeignKey('Rental', null=True, on_delete=models.CASCADE,verbose_name=_('Rental'), related_name="gallery")
        image = models.ImageField(blank=True,upload_to='upload/',null=True)

What am i missing?

Seán Hayes

You're using a Tastypie Paginator class, which automatically detects the current page based on the requests passed in to it, unlike the Django Paginator class which requires you to pass in the page index.

Here's the code with relevant comments: https://github.com/django-tastypie/django-tastypie/blob/master/tastypie/paginator.py#L26

Try this:

    paginator = Paginator(request.GET, sqs, limit=20)

    try:
        page = paginator.page()
    except InvalidPage:
        raise Http404("Sorry, no results on that page.")

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

page() takes 1 positional argument but 2 were given

From Java

TypeError: method() takes 1 positional argument but 2 were given

From Dev

Cant Solve "inc() takes 1 positional argument but 2 were given"

From Dev

Python: function takes 1 positional argument but 2 were given, how?

From Dev

TypeError: as_view() takes 1 positional argument but 2 were given

From Dev

TypeError: login() takes 1 positional argument but 2 were given

From Dev

Python: function takes 1 positional argument but 2 were given, how?

From Dev

Pygame TypeError: update() takes 1 positional argument but 2 were given

From Dev

python ,1 positional argument but 2 were given

From Dev

TypeError: __init__() takes 1 positional argument but 3 were given

From Dev

Python/Django: as_view() takes 1 positional argument but 2 were given

From Java

Django 2.1.3 Error: __init__() takes 1 positional argument but 2 were given

From Dev

TypeError: quit() takes 1 positional argument but 2 were given (keyboard bind)

From Dev

Django 2.1.3 Error: __init__() takes 1 positional argument but 2 were given

From Dev

Django client get: TypeError: __init__() takes 1 positional argument but 2 were given

From Dev

Django-registration-redux: get_success_url() takes 1 positional argument but 2 were given

From Dev

TypeError: add_log() takes 1 positional argument but 2 were given Not obvious

From Dev

Caught up in a Type Error: __init__() takes 1 positional argument but 2 were given

From Dev

Odoo takes from 1 to 2 positional arguments but 3 were given

From Dev

send_email() takes 1 positional argument but 3 were given - Django Python

From Dev

TypeError: init_animals() takes 1 positional arguments but 2 were given

From Dev

Money and TypeError: __init__() takes from 1 to 2 positional arguments but 3 were given

From Dev

TypeError: predict() takes from 1 to 2 positional arguments but 4 were given, google cloud shell

From Dev

TypeError: init_animals() takes 1 positional arguments but 2 were given

From Dev

Money and TypeError: __init__() takes from 1 to 2 positional arguments but 3 were given

From Dev

Python: __init__() takes 2 positional arguments but 3 were given

From Dev

TypeError: open() takes 0 positional arguments but 2 were given

From Dev

TypeError: _transform() takes 2 positional arguments but 3 were given

From Dev

Unexpected error: replace() takes 2 positional arguments but 3 were given

Related Related

  1. 1

    page() takes 1 positional argument but 2 were given

  2. 2

    TypeError: method() takes 1 positional argument but 2 were given

  3. 3

    Cant Solve "inc() takes 1 positional argument but 2 were given"

  4. 4

    Python: function takes 1 positional argument but 2 were given, how?

  5. 5

    TypeError: as_view() takes 1 positional argument but 2 were given

  6. 6

    TypeError: login() takes 1 positional argument but 2 were given

  7. 7

    Python: function takes 1 positional argument but 2 were given, how?

  8. 8

    Pygame TypeError: update() takes 1 positional argument but 2 were given

  9. 9

    python ,1 positional argument but 2 were given

  10. 10

    TypeError: __init__() takes 1 positional argument but 3 were given

  11. 11

    Python/Django: as_view() takes 1 positional argument but 2 were given

  12. 12

    Django 2.1.3 Error: __init__() takes 1 positional argument but 2 were given

  13. 13

    TypeError: quit() takes 1 positional argument but 2 were given (keyboard bind)

  14. 14

    Django 2.1.3 Error: __init__() takes 1 positional argument but 2 were given

  15. 15

    Django client get: TypeError: __init__() takes 1 positional argument but 2 were given

  16. 16

    Django-registration-redux: get_success_url() takes 1 positional argument but 2 were given

  17. 17

    TypeError: add_log() takes 1 positional argument but 2 were given Not obvious

  18. 18

    Caught up in a Type Error: __init__() takes 1 positional argument but 2 were given

  19. 19

    Odoo takes from 1 to 2 positional arguments but 3 were given

  20. 20

    send_email() takes 1 positional argument but 3 were given - Django Python

  21. 21

    TypeError: init_animals() takes 1 positional arguments but 2 were given

  22. 22

    Money and TypeError: __init__() takes from 1 to 2 positional arguments but 3 were given

  23. 23

    TypeError: predict() takes from 1 to 2 positional arguments but 4 were given, google cloud shell

  24. 24

    TypeError: init_animals() takes 1 positional arguments but 2 were given

  25. 25

    Money and TypeError: __init__() takes from 1 to 2 positional arguments but 3 were given

  26. 26

    Python: __init__() takes 2 positional arguments but 3 were given

  27. 27

    TypeError: open() takes 0 positional arguments but 2 were given

  28. 28

    TypeError: _transform() takes 2 positional arguments but 3 were given

  29. 29

    Unexpected error: replace() takes 2 positional arguments but 3 were given

HotTag

Archive