3

出于某种原因,我收到了错误:

TypeError: search_products() takes at least 2 arguments (2 given)

奇怪的是,我在两个不同的地方进行了相同的 API 调用——一个在我放置在 Model 类之一中的函数中。页面视图中的另一个。模型类中的一个工作正常,而 View 函数中的一个正在抛出错误。

以下是我在 Views.py 中的代码:

searchproducts=api.API().search_products(query="myproduct")

同样,当我在 Models.py 中编写完全相同的代码时,一切正常。

我在 api.py 的 API 类中的 search_products 函数如下:

def search_products(self, category_id, query="", start=0, limit=10, filter=None, ranged_filters=None, sort_by=None):

我怎样才能更深入地找到发生这种情况的根源?

追溯:

/Users/me/Desktop/myenv2/lib/python2.7/site-packages/django/core/handlers/base.py in get_response
                # Apply view middleware
                for middleware_method in self._view_middleware:
                    response = middleware_method(request, callback, callback_args, callback_kwargs)
                    if response:
                        return response
                try:
                    response = callback(request, *callback_args, **callback_kwargs) ...
                except Exception, e:
                    # If the view raised an exception, run it through exception
                    # middleware, and if the exception middleware returns a
                    # response, use that. Otherwise, reraise the exception.
                    for middleware_method in self._exception_middleware:
                        response = middleware_method(request, e)
4

1 回答 1

4

In your definition of search_products you have category_id as a required field, and you are not providing that as an argument when you are calling the method. Provide a default for category_id or pass in the appropriate argument to resolve your issue

于 2012-10-07T05:05:46.027 回答