Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Django 获取错误搜索_products()至少需要2个参数(给定2个)_Django - Fatal编程技术网

Django 获取错误搜索_products()至少需要2个参数(给定2个)

Django 获取错误搜索_products()至少需要2个参数(给定2个),django,Django,出于某种原因,我得到了错误: TypeError: search_products() takes at least 2 arguments (2 given) 奇怪的是,我在两个不同的地方进行了相同的API调用——一个在我放在一个模型类中的函数中。页面视图中的另一个。models类中的一个可以正常工作,而View函数中的一个可以返回错误 以下是我在Views.py中的代码: searchproducts=api.API().search_products(query="myproduct")

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

TypeError: search_products() takes at least 2 arguments (2 given)
奇怪的是,我在两个不同的地方进行了相同的API调用——一个在我放在一个模型类中的函数中。页面视图中的另一个。models类中的一个可以正常工作,而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)

search\u products
的定义中,您将
category\u id
作为必填字段,并且在调用该方法时未将其作为参数提供。为
category\u id
提供默认值,或传入适当的参数以解决问题