小编sam*_*sam的帖子

在Eve中,如何创建集合的子资源并保留父集合端点?

我想要这三个端点:

/games
/images
/games/<game_id>/images
Run Code Online (Sandbox Code Playgroud)

这是我的settings.py文件的摘录

#...

games = {
    "schema": {
        "title": {
            "type": "string",
            "required": True
        },
        "name": {
            "type": "string",
            "required": True
        },
    }
}

images = {
    "schema": {
        "game_id": {
            "type": "string",
            "required": True,
        },
        "title": {
            "type": "string",
            "required": True,
        },
    },
    "url": "games/<regex('[a-f0-9]{24}'):game_id>/images"
}
#...
Run Code Online (Sandbox Code Playgroud)

如果省略url属性,则在获取GET时会得到两个预期的端点:

/games

/images
Run Code Online (Sandbox Code Playgroud)

但是如果你包含url属性,则无法点击/ images,而只能点击/ games,/games/<game_id>/images如下所示:

{
    "_links": {
        "child": [
            {
                "href": "/games/<regex('[a-f0-9]{24}'):game_id>/images",
                "title": "games/<regex('[a-f0-9]{24}'):game_id>/images"
            },
            {
                "href": "/games",
                "title": "games"
            }
        ]
    }
}
Run Code Online (Sandbox Code Playgroud)

如何保留集合 …

python eve

5
推荐指数
1
解决办法
1478
查看次数

标签 统计

eve ×1

python ×1