2
回到這裏的數據是我的Python代碼EVE無法從Python的EVE API
from eve import Eve
from eve.auth import BasicAuth
class MyBasicAuth(BasicAuth):
def check_auth(self, username, password, allowed_roles, resource,
method):
if resource == 'auth':
user = app.data.driver.db['user']
user = user.find_one({'email': username,'password':password})
if user:
return user
else:
False
else:
return True
app = Eve(auth=MyBasicAuth)
if __name__ == '__main__':
app.run()
在驗證成功,我返回user
對象,但什麼都不會返回。我哪裏錯了。 這裏是settings.py文件
RESOURCE_METHODS = ['GET', 'POST']
DOMAIN = {
'user': {
'schema': {
'firstname': {
'type': 'string'
},
'lastname': {
'type': 'string'
},
'email': {
'type': 'string'
},
'password': {
'type': 'string'
},
'phone': {
'type': 'string'
}
}
},
'auth': {
'schema': {
'username': {
'type': 'string'
},
'password': {
'type':'string'
}
}
}
}
嘿..你好,'settings.py'中的錯誤更新爲包含auth端點。我正在嘗試編寫一個Auth API來驗證用戶名和密碼,並在成功驗證時返回用戶詳細信息。由於正在點擊的端點不是'user',所以'auth'可以告訴我如何返回用戶詳細信息。 – iJade