使用 Python EVE 的 RETURN_MEDIA_AS_URL 时如何在响应中找到关联资源的媒体 url

How can I find the associated resource's media url within the response when using Python EVE's RETURN_MEDIA_AS_URL

我在 settings.py 中启用了 RETURN_MEDIA_AS_URL。我有一个看起来像这样的架构:

schema = {
    'type': 'dict',
    'schema': {
        'action': {
            'type': 'string',
            'default': 'Favorite'
        },
        'description': {
            'type': 'string',
            'default': 'I really liked this.'
        },
        'hyperlink': {
            'type': 'string',
            'default': 'http://placehold.it/300x300'
        },
        'pic': {
            'type': 'media'
        }
    }
}

生成资源后,响应项负载如下所示:

{
  "_updated": "2015-05-06T17:30:32Z",
  "description": "I really liked this.",
  "hyperlink": "http://placehold.it/300x300",
  "pic": {
        "upload_date": "2015-05-06T17:30:32Z",
        "length": 119861,
        "content_type": "image/png",
        "file": null,
        "name": "shoebot.png"
   },
   "_links": {
       "self": {
            "href": "notification/554a4fb8803bd747eb725d4a",
            "title": "Notification"
       }
   },
   ...
}

我有一个 API 前缀,如下所示:/api/v1/ 我似乎无法弄清楚 GET url 会用我来自 Eve 的 shoebot.png 图片做出回应。

感谢您给我的建议,让我朝着正确的方向前进:-)

返回媒体,因为 URL 目前在 development branch,针对 v0.6 版本。因此,除非您是 development 分支的 运行,否则您还无法使用此功能。如果愿意,您当然可以将其拉下来并自由试验。

希望对您有所帮助。