Python Eve

时间:2017-04-17 23:23:26

标签: python eve

我无法弄清楚子资源在Python EVE中是如何工作的。 我试过这个:

DOMAIN = {
    'people':{
        'type': 'dict',
        'required': False,
        'schema':{
            'name':{
                'type':'string',
                'required':True
            },
            'id':{
                'type':'string',
                'required':True
            },
            'books':{
                'type': 'dict',
                "url": "people/<regex('[a-f0-9]{24}'):people_id>/books",
                'schema':{
                    'name':{
                        'type':'string',
                        'required':False
                    },
                    'id':{
                        'type':'string',
                        'required':False
                    }
                }
            }
        }
    }
}

现在,当我对URL进行POST时:     http://127.0.0.1:5000/people/58f5527d211d561ea1b35d8b/

带输入:     {         &#39; BOOKNAME&#39;:&#39;东西&#39 ;,         &#39; BOOKID&#39;:&#39; 1001&#39;     }

我得到&#34;请求的网址不允许这种方法。,但我有 RESOURCE_METHODS = [&#39; GET&#39; ,&#39;删除&#39;,&#39; POST&#39;] ITEM_METHODS = [&#39; GET&#39;,&#39; PATCH&#39;,&#39; PUT&#39;,&#39;删除&#39;] 允许的。

我知道我错过了发布子资源的正确方法,我找不到任何文档。提前谢谢。

1 个答案:

答案 0 :(得分:0)

您可以查看前夕演示设置文件,其中定义了simple sub-document

'schema': {
    'firstname': {
        'type': 'string',
        'minlength': 1,
        'maxlength': 10,
    },
    'lastname': {
        'type': 'string',
        'minlength': 1,
        'maxlength': 15,
        'required': True,
        'unique': True,
    },
    'role': {
        'type': 'list',
        'allowed': ["author", "contributor", "copy"],
    },
    # An embedded 'strongly-typed' dictionary.
    'location': {
        'type': 'dict',
        'schema': {
            'address': {'type': 'string'},
            'city': {'type': 'string'}
        },
    },
    'born': {
        'type': 'datetime',
    },
}

所以,回头看看你的代码片段,我会说你错过了'type': 'dict'对你的&#34;书籍的定义&#34;字段。