gpt4 book ai didi

python - Flask reSTLess 无法构造查询

转载 作者:行者123 更新时间:2023-11-30 23:09:27 25 4
gpt4 key购买 nike

我有两个 Flask-SQLAlchemy 模型和各自的 Flask-ReSTLess API 端点,如下所示:

class Person(db.Model):
person_id = db.Column(db.Integer, primary_key=True)
document = db.Column(db.String(), unique=True)
name = db.Column(db.String(45))

class Student(db.Model):
student_id = db.Column(db.Integer, primary_key=True)
person_id = db.Column(db.Integer, db.ForeignKey('person.person_id'))
code = db.Column(db.String(45))

person = db.relationship('Person', backref=db.backref('students', lazy='dynamic'))

manager.create_api(Person, methods=['GET', 'POST'])
manager.create_api(Student, methods=['GET', 'POST'])

这些 URL 工作正常:

  • http://localhost:8080/api/person
  • http://localhost:8080/api/student

但是当我尝试按照 official docs 中所述对相关模型进行搜索查询时,我收到这些请求的 { "message": "Unable to Construction query"}:

  • http://localhost:8080/api/person?q={"filters":[{"name":"students__code","op":"eq","val": “1”}]}

  • http://localhost:8080/api/person?q={"filters":[{"name":"students","op":"has","val": {"name":"code","op":"eq","val":"1"}}]}

  • http://localhost:8080/api/student?q={"filters":[{"name":"person__document","op":"eq","val": “111”}]}

  • http://localhost:8080/api/student?q={"filters":[{"name":"person","op":"any","val": {"name":"document","op":"eq","val":"111"}}]}

我正在使用 Flask 0.10.1、Flask-SQLAlchemy 2.0、Flask-ReSTLess 0.17.0、SQLAlchemy 1.0.6 和 Python 2.7。

最佳答案

查询中的数值不应加引号。

错误:

"val":"1"

正确:

"val":1

关于python - Flask reSTLess 无法构造查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31199439/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com