python - 过滤/子请求以获得结果

标签 python api eve

Mongodb

 db.entity.find()
{
        "_id" : ObjectId("5563a4c5567b3104c9ad2951"),
        "section" : "section1",
        "chapter" : "chapter1",
        ...
},
{
        "_id" : ObjectId("5563a4c5567b3104c9ad2951"),
        "section" : "section1",
        "chapter" : "chapter2",
        ...
},....

在我的数据库中,entity 集合主要包含sectionchapter。只有 chapter 值是唯一的,当我们为给定部分查询 mongo 时,它将返回多个结果(一个部分与许多章节匹配)。

我需要做的是获取给定部分的所有集合,就这么简单。

settings.py

URL_PREFIX = "api"

API_VERSION = "v1"

ALLOWED_FILTERS = ['*']

schema = {
    'section': {
        'type': 'string',
    },  
    'chapter': {
        'type': 'string',
    },
}

entity = {
    'item_title': 'entity',
    'resource_methods': ['GET'],

    'cache_control': '',
    'cache_expires': 0,

    'url': 'entity/<regex("\w+"):section>/section',

    'schema': schema
}

DOMAIN = {
    'entity': entity,
}

run.py

from eve import Eve

if __name__ == '__main__':                      
    app.run(debug=True)   

What I tried

curl -L -X GET -H 'Content-Type: application/json' http://127.0.0.1:5000/api/v1/entity/23/section

OUTPUT

{ 
  "_status": "ERR",
  "_error": {
    "message": "The requested URL was not found on the server.  If you entered the URL manually please check your spelling and try again.",
    "code": 404
  }
}

我做错了什么?如何获取一个部分的所有实体?

最佳答案

你试过这样写url吗:

http://127.0.0.1:5000/api/v1/entity?where=section=='section32'

请看看这个 python-eve.org/features.html#filtering

关于python - 过滤/子请求以获得结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30682094/

相关文章:

python - 以不一致的间隔切片 Python 列表

excel - 如何使用 OpenXML API 从 Excel 电子表格读取表格?

python - 如何更改单个文档值的架构类型

python - 如何使用 eve 从同一个键请求多个值

python - 自定义 Django 登录页面不呈现登录表单

python - 如何从python中的周数中获取日期列表

android - android 上是否有用于 pandora 的开发者 api?

javascript - WSGI 与 python eve [Errno 32] 管道损坏... Ajax 调用

python cv2数组到numpy

api - 使用两因素身份验证的 instagram api 登录