can't search eve rest API - additional lookup not working

耗尽温柔 提交于 2019-12-06 09:44:37

In your settings.py you aren't doing the lookup correctly. It should be.

apps = {
    'item_title' : 'app',

    'additional_lookup' : {
    'url' : 'apps/regex("\b[\w.-]+?@\w+?\.\w+?\b")',
    'field' : 'developer_email',
    },

        'schema': {
            'address' : {
                'type' : 'string'
                },
            'developer_email' : {
                'type' : 'string',
                'minlength' : 1,
                'maxlength' : 15,
                'required' : True,
                'unique' : True,
            }
            }
Thomas2D

You can't add more than one additional lookup to the same endpoint. What you can do however, is have multiple endpoints consuming the same datasource. By default standard item entry point is defined as /apps/'objectID'/. You will have to configure another endpoint to /apps/'new endpoint'. Python-Eve: More than one additional lookup

@Vorticity pointed out a fix in a related question. Try the following:

'additional_lookup': {
    'url': 'regex("[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$")',
    'field': 'developer_email'
}

You should be able to retrieve your item with or without url encoding eg:

localhost:5000/apps/example@gmail.com
localhost:5000/apps/example%40gmail.com

If you have any interest in making your items retrievable at the item level by email _only (not object id), you can use item_lookup_field together with item_url:

apps = {
    ...
    'item_url': 'regex("[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$")',
    'item_lookup_field': 'developer_email'
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!