can't search eve rest API - additional lookup

2019-05-28 11:13发布

I was following the example here: https://github.com/pyeve/eve-demo/blob/master/settings.py

When I go to localhost:5000/apps, I can see all the documents in my collection, but when I search for an email at localhost:5000/apps/example@gmail.com, it says '404 not found'.

I've confirmed the regex, and the email addresses are in the documents. Can anyone see what might be wrong?

run.py

from eve import Eve


if __name__ == '__main__':
    app = Eve()
    app.run()

settings.py:

RESOURCE_METHODS = ['GET', 'POST', 'DELETE']
ITEM_METHODS = ['GET', 'PATCH', 'PUT', 'DELETE']


MONGO_HOST = 'localhost'
MONGO_PORT = 27017
MONGO_DBNAME = 'test_database'



apps = {
    'item_title' : 'app',

    'additional_lookup' : {
    'url' : '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,
            }
            }

DOMAIN = {
    'apps' : apps,
}

标签: python rest eve
2条回答
贼婆χ
2楼-- · 2019-05-28 11:33

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

查看更多
Lonely孤独者°
3楼-- · 2019-05-28 11:34

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,
            }
            }
查看更多
登录 后发表回答