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,
}
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,
}
}
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'
}
来源:https://stackoverflow.com/questions/43838785/cant-search-eve-rest-api-additional-lookup-not-working