TypeError:process_query()缺少1个必需的位置参数:“ query”

时间:2019-07-08 15:28:40

标签: flask orm flask-restful

我在process_query()函数中遇到此错误。

我正在使用Flask,Flask_restuful,演说家Orm。

您能帮助我解决此错误吗?

谢谢。

python:

型号:

def process_query(self, query_str):
    domains = re.findall(r"(?P<field>[a-z_]*)"
                         r"(?P<operator>=|<|>|>=|<=)"
                         r"(?P<value>[^&]*)&*", query_str)
    m = self
    for domain in domains:
        field, operator, value = domain
        m = m.where(field, operator, value)
    return m

资源

class ItemList(Resource):
    parser = reqparse.RequestParser()
    parser.add_argument('query',
                        type=str)

    def get(self):
        data = ItemList.parser.parse_args()
        query_str = data.get('query')
        model = ItemModel
        if query_str:
            model = ItemModel.process_query(query_str)
        return self.render_results_with_pagination(model)

    @staticmethod
    def render_results_with_pagination(filtered_itemlist):
        page, per_page, offset = get_page_args(page_parameter='page',
                                               per_page_parameter='per_page')
        total = filtered_itemlist.count()
        p_alerts = filtered_itemlist.paginate(per_page, page)
        pagination = Pagination(page=page, per_page=per_page, total=total,
                                css_framework='bootstrap4')

        res = render_template('index.html',
                              pagination_alerts=p_alerts,
                              page=page,
                              per_page=per_page,
                              pagination=pagination)
        headers = {'Content-Type': 'text/html'}
        return make_response(res, 200, headers)

0 个答案:

没有答案